The examples in this article describe how Android simply acquires latitude and longitude. Share to everyone for your reference, specific as follows:
public void Getloc () {//position Locationmanager Locationmanager;
Locationlistener Locationlistener;
Location Location;
String contextservice = Context.location_service;
String provider;
Double lat;
Double lon;
Locationmanager = (Locationmanager) getsystemservice (Contextservice);
Criteria criteria = new criteria (); Criteria.setaccuracy (criteria.accuracy_fine);//High precision criteria.setaltituderequired (false);/No elevation Criteria.setbea Ringrequired (false);//does not require azimuth criteria.setcostallowed (true);//Allow cost criteria.setpowerrequirement (criteria.power_
/low power//low-power//from the available location provider, the best provider Provider = Locationmanager.getbestprovider (criteria, true) that matches the above criteria;
Get the position of the last change location = Locationmanager.getlastknownlocation (provider); Locationlistener = new Locationlistener () {public void onstatuschanged (String provider, int status, Bundle extr AS) {//TODO auto-generated method stub} public VoiD onproviderenabled (String provider) {//TODO auto-generated method stub} public void Onproviderdisabled (
String provider) {//TODO auto-generated method stub} public void Onlocationchanged (Location Location) {
lat = Location.getlatitude ();
lon = Location.getlongitude ();
LOG.E ("Android_lat", string.valueof (LAT));
LOG.E ("Android_lon", String.valueof (Lon));
}
};
Monitoring position changes, 2 seconds, distance of more than 10 meters locationmanager.requestlocationupdates (provider,,,, Locationlistener);
}
More interested readers of Android-related content can view the site: Android Development Primer and Advanced tutorials, the Android View View tips Summary, the activity tips summary of Android programming, Android Operation SQLite Database skills Summary, "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", "Android File Operation skills Summary", "Android programming development of SD card operation method Summary", " Android Resource Operation tips Summary and the "Android Controls usage Summary"
I hope this article will help you with the Android program.