Based from this thread, you can also connect to the Emulator via Telnet. You then have a Emulator console that lets you enter certain data like geo fixes, network etc.
How to use the console is extensively explained
here.
To connect to the console open a command line and type
telnet localhost 5554
You then can use the geo command to set a latitude, longitude and if
needed altitude on the device that is passed to all programs using the
gps location provider. See the link above for further instructions.
The specific command to run in the console is
geo fix <longitude value> <latitude value>
According to the documentation, getLastKnownLocation
method can return null. In that case you should wait for location updates (you can user requestLocationUpdates method from LocationManager). You can trigger location update on emulator's gps module by following command: adb -e emu geo fix 50 50
.
You should also use LocationManager.GPS_PROVIDER
. The emulator may not appear to respond to location changes sent via DDMS when the provider is set to NETWORK_PROVIDER, but will when it is set to GPS_PROVIDER. Check this link.