Android mobile phone positioning case code and android positioning case
The Code is as follows:
Package com. xuliugen. gpsdemo; import com. itheima. gpsdemo. r; import android. app. activity; import android. location. criteria; import android. location. location; import android. location. locationListener; import android. location. locationManager; import android. OS. bundle; import android. widget. textView;/*** mobile phone locator code ** @ author xuliugen **/public class MainActivity extends Activity {// use location service private LocationManager lm; private MyLocationListener listener; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); lm = (LocationManager) getSystemService (LOCATION_SERVICE); // obtain the location method. // List <String> provider = lm. getAllProviders (); // for (String l: provider) {// System. out. println (l); //} listener = new MyLocationListener (); // register the listening location service // set the condition Criteria criteria = new Criteria () for the location provider; criteria. setAccuracy (Criteria. ACCURACY_FINE); // you can specify the following parameters: // criteria. setAccuracy (Criteria. ACCURACY_FINE); // sets it to the maximum precision. // criteria. setAltitudeRequired (false); // The elevation information is not required. // criteria. setBearingRequired (false); // The orientation information is not required. // criteria. setCostAllowed (true); // whether to allow payment // criteria. setPowerRequirement (Criteria. POWER_LOW); // power requirement String proveder = lm. getBestProvider (criteria, true); lm. requestLocationUpdates (proveder, 0, 0, listener) ;}@ Override protected void onDestroy () {// TODO Auto-generated method stub super. onDestroy (); // cancel listening location service lm. removeUpdates (listener); listener = null;} class MyLocationListener implements LocationListener {/*** callback when the Location changes */public void onLocationChanged (location Location) {String longpolling = "longitude:" + location. getlongpolling (); String latitude = "latitude:" + location. getLatitude (); String accuracy = "precision:" + location. getAccuracy (); TextView textview = new TextView (MainActivity. this); textview. setText (longmargin + "\ n" + latitude + "\ n" + accuracy); setContentView (textview);}/*** enable callback when the status changes -- disable; close -- enable */public void onStatusChanged (String provider, int status, Bundle extras) {}/*** a location provider can use */public void onProviderEnabled (String provider) {}/*** a location provider cannot use */public void onProviderDisabled (String provider ){}}}