Android getlastknownlocation () solution to obtain the null location

Source: Internet
Author: User

Developing with the Google map API is a tangle

When getlastknownlocation () is used, the value cannot be obtained inexplicably. If it is null, then it is inexplicably better. After debugging for a long time, it is useless. If you go online to find information, you will get an answer from the previous article.

So let it survive in the future.

Locationmanager = (locationmanager) getsystemservice (context. location_service); Criteria = new criteria (); criteria. setaccuracy (criteria. accuracy_fine); string provider = locationmanager. getbestprovider (criteria, true); locationmanager. requestlocationupdates (provider, 2000, 0, this );
Mostrecentlocation = locationmanager. getlastknownlocation (provider );

You don't need to write more of these six sentences!

At the same time, the current location is not accurate. I don't know how Google uses it. Is it because I have not practiced enough?

After testing, we found that,

Add a while (mostrecentlocation = NULL)

So it will keep searching, and it will be found in about 3 minutes, so be patient.

If you are confused, try it !!

 

In the end, I still want to develop JS web pages. Why should I withdraw it to Android Java?

My thinking is sometimes correct, that is, I cannot grasp the details, and I am inexplicably excited about the inexplicable bugs. I have no patience in solving these problems.

This is a problem!

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.