GeoLocation App not working on Android Emulator

2019-09-07 13:18发布

问题:

I am testing a Geo-location App using an Emulator created in Android Studio. I have passed the latitude and longitude using DDMS which seems to work. I confirmed it by going to Google and checking the location. The location changes based on any changes on the Lat/Long. However, the App under test is not getting any location information. The App displays that the location services is not turned on when in fact it is turned on and working fine. Is there a specific command that can target the App on the emulator? I also have tried Geo fix commands but experiencing the same issue.

回答1:

this worked for me once. Best is to use actual device as there is no guarantee that it will work everytime.

The Android 2.x simulators will not return a geolocation result unless the enableHighAccuracy option is set to true.

Also use this in your code

 navigator.geolocation.getCurrentPosition(onSuccess, onError, 
{
 maximumAge: 2000, timeout: 10000, enableHighAccuracy: true 
});

and use telnet in emulator to enter fixed co-ordinates

samvid@locahost:~$ telnet localhost 5554 
Trying 127.0.0.1... Connected to localhost.localdomain.
 Escape character is '^]'. 
Android Console: type 'help' for a list of commands 
OK 
geo fix 39.09091 27.44011
OK 
quit 
Connection closed by foreign host.

You can read more about it here.