Sunday, August 19, 2012

Android - Sending GPS Location to Emulator



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.

No comments:

Post a Comment