We all know that we need to simulate GPS on the simulator during development, but the Location is always null. After checking the internet, we found the following solution:
Solutions for online heroes:
When obtaining GPS information on the simulator, use Location loc = LocationManager. getLastKnownLocation ("gps"); To obtain location information, but loc is usually null in debugging, because you need to manually add GPS information to the simulator first, there are two ways to manually add
1. In eclipse, manually set the longitude and latitude under windows --> open perspective --> DDMS --> Emulator control --> Manual, and press the send button. However, this method has passed my tests and is valid only after the following methods are used.
2. You can also manually add information under cmd.
(1) first open the simulator, run cmd, and enter telnet localhost 5554 (Note: 5554 is the port of the simulator on the local machine. It may be different. The specific port number, in the upper-left corner of the simulator ).
Android Console: type 'help' for a list of commands OK.
If you are a friend of WIN7, the console may prompt that telnet is invalid or something, because telnet is not displayed by default in WIN7 and needs to be opened manually. Specifically: [1] control panel --> program --> enable or disable the Windows function, and then select the Telnet server and Telnet client. [2] Then manually start Telnet in management tools> services
(2) Use the geo command to simulate GPS signal sending:
Geo fix Longitude Latitude
(3) a gps mark is added to the status bar of the simulator ~ Use Location loc = LocationManager. getLastKnownLocation ("gps") to obtain the coordinates ~~
After I performed the operation, I found that the error was reported, and there was still no small GPS indicator icon. I don't know why. the above solution gave me a prompt, I think the simulator does not enable GPS, and it does not work in system settings. later, I simply ran google map on the simulator. This time, the gps indicator icon was displayed, and then the location method was called. Note that gps must be specified to locate the problem, otherwise, an error is reported.