I want to get longitude and latitude in android emulator for testing.
Can any one guide me how to achieve this?
How do I set the location of the emulator to a test position?
I want to get longitude and latitude in android emulator for testing.
Can any one guide me how to achieve this?
How do I set the location of the emulator to a test position?
Assuming you've got a mapview set up and running:
MapView mapView = (MapView) findViewById(R.id.mapview);
final MyLocationOverlay myLocation = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocation);
myLocation.enableMyLocation();
myLocation.runOnFirstFix(new Runnable() {
public void run() {
GeoPoint pt = myLocation.getMyLocation();
}
});
You'll need the following permission in your manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
And to send mock coordinates to the emulator from Eclipse, Go to the "Window" menu, select "Show View" > "Other" > "Emulator control", and you can send coordinates from the emulator control pane that appears.
You can 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.
If you need more then one coordinate you can use a kml file with a route as well it is a little bit described in this article. I can't find a better source at the moment.
I was trying to set the geo fix through adb for many points and could not get my app to see any GPS data. But when I tried opening DDMS, selecting my app's process and sending coordinates through the emulator control tab it worked right away.
I was looking for a better way to set the emulator's GPS coordinates than using geo fix
and manually determining the specific latitude and longitude coordinates.
Unable to find anything, I put together a little program that uses GWT and the Google Maps API to launch a browser-based map tool to set the GPS location in the emulator:
Hopefully it can be of use to help others who will undoubtedly stumble across this difficulty/question as well.
Notes: