下面是我正在使用的位置监听器和调用它的方法。当我运行此地图时,地图会不断放大和缩小。我目前在我的活动中从 onCreate 调用它。我在这里做错了什么?
private void showCurrentLocationOnMap(){
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
LocationListener ll = new Mylocationlistener();
boolean isGPS = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!isGPS){
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
/**
*Mylocationlistener class will give the current GPS location
*with the help of Location Listener interface
*/
private class Mylocationlistener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
if (location != null) {
// ---Get current location latitude, longitude, altitude & speed ---
Log.d("LOCATION CHANGED", location.getLatitude() + "");
Log.d("LOCATION CHANGED", location.getLongitude() + "");
currentLocation = new LatLng(location.getLatitude(), location.getLongitude());
HAMBURG = new LatLng(location.getLatitude(), location.getLongitude());
//This only shows the initial marker
@SuppressWarnings("unused")
Marker hamburg = map.addMarker(new MarkerOptions().position(currentLocation).title("Current Location"));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null);
}
}