How to emulate GPS location in the Android Emulator?

前端 未结 30 2361
天命终不由人
天命终不由人 2020-11-21 22:15

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

30条回答
  •  日久生厌
    2020-11-21 22:49

    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:

    
    

    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.

提交回复
热议问题