Can I use an external GPS receiver by connecting both GPS and Android device to a PC? I have an HTC One X which I like and carry everywhere, but the GPS is atrocious.  It takes tens of minutes to get a position, loses it easily and it's not even very accurate when it has a signal.  However, I also have a Garmin GPS which is fantastic at gaining and holding a steady and accurate GPS location.  I'd like to use the Garmin as an external GPS in combination with android's mock-location feature, in my car.

It is definitely possible to drive gpsd on a pc with the garmin - but I don't know how to use that to provide location data to android.  The phone is already rooted and I'm not averse to hacking it a bit more, but of course simpler solutions are preferred.  Initially I would be happy plugging the Garmin and HTC into a laptop but I'll move to a Raspberry Pi as soon as I know it works.  Not really bothered about using USB OTG to connect as this is for in-car use.

So: Can I use gpsd running on a PC to control a mock-location on Android?  If so, how?
I don't know if you can do this with your PC. Likely the easiest way would be to hack up a custom script on your PC to respond to new positions coming from gpsd, and use the following command to mock those locations on the phone:

adb shell setLatLon latitude longitude

You need to have previously turned on USB debugging and mock locations in the phone's settings.

However, this seems unnecessarily complicated. If you search for external gps on Google Play, you'll see a zillion apps that allow you to connect your Android device directly to an external GPS receiver. There's no need to involve your PC at all. Try a few and report back which one works best for you.