0

我在 onCreate() 中有一个代码

LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(  
LocationManager.GPS_PROVIDER, 500, 1, new LocationListener (){
             @Override
             public void onLocationChanged(Location loc) {
                               CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(loc.getLatitude(), loc.getLongitude()));
                               myMap.moveCamera(center);  
             }
});

当更改用户的位置时会发生这种情况,但我希望它发生一次。我想等到收到新位置后再移动到新的位置地图,然后不将地图移动给用户

4

1 回答 1

1

班级成员

private LocationManager mLocationManager; 
MyLocationListener mLocationListener 

locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
MyLocationListener mLocationListener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 1, myLocationListener);

public MyLocationListener extends LocationListener
{
        @Override
        public void onLocationChanged(Location loc) {
              CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(loc.getLatitude(), loc.getLongitude()));
              myMap.moveCamera(center); 
              mLocationManager.removeUpdates(mLocationListener): 
             }

        @Override
        public void onProviderDisabled(String provider) 
         {

         }

        @Override
        public void onProviderEnabled(String provider) 
        {

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) 
        {

        }

}
于 2013-05-11T21:45:25.023 回答