Android Google map API positioning to obtain latitude and longitude

Source: Internet
Author: User
private LocationManager locationManager;
Locationmanager = (locationmanager) getsystemservice (context. location_service); locationmanager. requestlocationupdates (locationmanager. gps_provider, 1000, 5, new mylocationlistener (); location = locationmanager. getlastknownlocation (locationmanager. gps_provider); If (location! = NULL) {system. out. println ("***************"); system. out. println ("longitude:" + location. getlongpolling (); system. out. println ("latitude:" + location. getlatitude ();} else {system. out. println ("Null Pointer ");}

Class mylocationlistener implements locationlistener {public void onlocationchanged (location) {Show. settext ("user location changed" + "\ N longitude:" + location. getlongpolling () + "\ N latitude:" + location. getaltitude () + "\ n data accuracy:" + location. getaccuracy () + "\ n time:" + location. gettime () + "\ n speed:" + location. getspeed () + "\ n Direction:" + location. getbearing ();} public void onproviderdisabled (string provider) {} public void onproviderenabled (string provider) {} public void onstatuschanged (string provider, int status, bundle extras ){}}

It is explained here because it is not the complete code, it is only a small module. For your use, we declare in advance that it is okay to run these lines of code in the wify on the real machine. But when the mobile phone network is mobile data, it will not work and I don't know what's going on, maybe this is why many people don't like Google's location system, but I think it's okay. I personally disagree and don't want to spray it. I also like Baidu map very much. I will prepare for research in a few days.

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.