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.