【网学网提醒】:网学会员为需要朋友们搜集整理了Android GPS获取地理位置相关资料,希望对各位网友有所帮助!
AndroidGPS获取地理位置
importandroid.app.Activity;1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.e);18.19.20.21.22.23.24.25.26.27.28.;29.30.31.32.33.{34.35.36.publicvoidonLocationChanged(Locationlocation){updateWithNewLocation(location);}}privatefinalLocationListenerlocationListener=newLocationListener()updateWithNewLocation(location);locationManager.requestLocationUpdates(provider,2000,10,locationListener);Locationlocation=locationManager.getLastKnownLocation(provider)Criteriacriteria=newCriteria();criteria.setAccuracy(Criteria.ACCURACY_FINE);criteria.setAltitudeRequired(false);criteria.setBearingRequired(false);criteria.setCostAllowed(true);criteria.setPowerRequirement(Criteria.POWER_LOW);Stringprovider=locationManager.getBestProvider(criteria,true);//Stringprovider=LocationManager.GPS_PROVIDER;publicclassCurrentLocationextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);LocationManagerlocationManager;StringserviceName=Context.LOCATION_SERVICE;locationManager=(LocationManager)getSystemService(serviceNamimportandroid.content.Context;importandroid.location.Criteria;importandroid.location.Location;importandroid.location.LocationListener;importandroid.location.LocationManager;importandroid.os.Bundle;importandroid.widget.TextView;
37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.}}};
publicvoidonProviderDisabled(Stringprovider){updateWithNewLocation(null);}publicvoidonProviderEnabled(Stringprovider){}publicvoidonStatusChanged(Stringprovider,intstatus,Bundleextras){}privatevoidupdateWithNewLocation(Locationlocation){StringlatLongString;TextViewmyLocationText;myLocationText=(TextView)findViewById(R.id.myLocationText);if(location!=null){doublelat=location.getLatitude();doublelng=location.getLongitude();latLongString="纬度:"+lat+"\n经度:"+lng;}else{latLongString="无法获取地理信息";}myLocationText.setText("您当前的位置是:\n"+latLongString);