首先检查最近知道的位置是否是最近的。如果没有,我相信您必须设置onLocationChanged侦听器,但是一旦获得第一个有效位置,就可以随时停止更新流。
加成
public class Example extends Activity implements LocationListener { LocationManager mLocationManager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if(location != null && location.getTime() > Calendar.getInstance().getTimeInMillis() - 2 * 60 * 1000) { // Do something with the recent location fix // otherwise wait for the update below } else { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } } public void onLocationChanged(Location location) { if (location != null) { Log.v("Location Changed", location.getLatitude() + " and " + location.getLongitude()); mLocationManager.removeUpdates(this); } } // Required functions public void onProviderDisabled(String arg0) {} public void onProviderEnabled(String arg0) {} public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}}


