The solution to simulating the GPS function on the Android simulator is always null.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.