The solution to simulate the GPS function on the Android simulator is always null _android

Source: Internet
Author: User
As we all know, we need to simulate GPS on the simulator when we develop, we can always null in the location, check the Internet, and find the following solutions:

Online Warrior's Solution:
When acquiring GPS information on the simulator, the location loc = locationmanager.getlastknownlocation ("GPs") is used to obtain location information, but often in debugging Loc is null. Because you first need to manually add GPS information to the emulator, there are two ways to add it manually
1, under Eclipse, Windows-->open perspective-->ddms-->emulator control-->manual manually set latitude and longitude, and press the Send button. But this method has been tested by me and needs to be based on the following methods.

2, under the CMD can also manually add information.

(1) First open the simulator, and then run cmd, input telnet localhost 5554 (note: 5554 is the simulator in this machine port, there may not be the same as HA, specific port number, simulator left the top of the display), this will appear
Android console:type ' help ' for a list of commands ok.

If you are using WIN7 's friends, the console may be prompted for Telnet to be invalid or something, because Telnet is not present under WIN7, and it needs to be opened manually. Specifically: [1] Control Panel--> program--> turn on or off Windows features, and then check the Telnet server and Telnet client. [2] Then manually start Telnet in the admin tools--> Service

(2) Use GEO command to simulate sending GPS signal:
Geo Fix longitude latitude

(3) At this time will find in the simulator's status bar more than a GPS logo ~ Then use location loc = Locationmanager.getlastknownlocation ("GPs"), you can get to the location of the coordinates ~ ~
I actually did some work and found that I was still reporting the error, still did not appear the GPS small indicator icon, do not know what the reason. The above solution gave me a hint, I think the simulator does not turn on the GPS, in the system setup has no effect to enable. Then I ran the Google map directly on the simulator, This time the advent of the GPS indicator icon, and then call to obtain location method on it, but also note that the GPS must be specified to locate, if it is another way or will report errors

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.