How to emulate GPS location in the Android Emulator?

前端 未结 30 2339
天命终不由人
天命终不由人 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:48

    Just make Alberto Gaona's answer into one line

    token=$(cat ~/.emulator_console_auth_token); cat <(echo -e "auth $token \n  geo fix 96.0290791 16.9041016  \n exit") - | nc localhost 5554
    

    5554 is the emulator port number shown in adb devices.

    It would have been better if adb emu work.

    0 讨论(0)
  • 2020-11-21 22:48

    If the above solutions don't work. Try this:

    Inside your android Manifest.xml, add the following two links OUTSIDE of the application tag, but inside your manifest tag of course

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
    <uses-permission android:name="android.permission.INTERNET" ></uses-permission>
    
    0 讨论(0)
  • 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:

    <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.

    0 讨论(0)
  • 2020-11-21 22:50

    The following solution worked for me - open command line and write:

    adb emu geo fix [longtitude] [latitude]
    
    0 讨论(0)
  • 2020-11-21 22:50

    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.

    0 讨论(0)
  • 2020-11-21 22:53

    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.

    The specific command to run in the console is

    geo fix <longitude value> <latitude value>
    

    I found this site useful for finding a realistic lat/lng: http://itouchmap.com/latlong.html

    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.

    0 讨论(0)
提交回复
热议问题