Emulating GPS functionality on Android emulators is always the solution for null

  • 2020-05-10 18:52:26
  • OfStack

As we all know, we need to simulate GPS on the simulator when we are developing, but null always works on Location. After checking the Internet for 1, we found the following solutions:

Solutions for online heroes:
When obtaining GPS information on the emulator, Location loc = LocationManager. getLastKnownLocation("gps"); To get location information, but loc is usually null in debugging, because you need to manually add GPS information in the emulator first. There are two ways to manually add GPS information
1. Under eclipse, windows-- > open perspective-- > DDMS-- > Emulator control-- > Under Manual, manually set the latitude and longitude, and press the send button. However, this method has been tested by me and only works based on the following method

2. You can also manually add information under cmd.

(1) first open the emulator, then run cmd, and enter telnet localhost 5554(note: 5554 is the port of the emulator on the machine, it may not be the same, the specific port number is shown in the upper left of the emulator), so it will appear
Android Console: type 'help' for a list of commands OK

If you are a friend using WIN7, the console may tell you that telnet is invalid or something, because telnet does not appear under WIN7 by default, you need to open it manually. Specifically: [1] control panel -- > Program - > Turn Windows on or off, then tick the Telnet server and Telnet client. [2] then in the management tool -- > Start Telnet manually in the service

(2) simulate GPS signal sending by geo command:
geo fix latitude and longitude

(3) at this time, it will be found that there is an extra GPS symbol in the status bar of the simulator ~ Location loc = LocationManager.getLastKnownLocation ("gps"); I can get the position of this coordinate ~~
I practice 1, discover or report an error, or no GPS little indicator icon, don't know is what reason. The solution to the above gave me a tip, I think is not open GPS simulator, enable no effect in the system Settings. Then I simply run directly on the simulator google map, this appeared gps indicator icon, then call get location method, also note that must be specified using gps to positioning, will report an error if there is other way

Related articles: