1

下面是我正在使用的位置监听器以及调用它的方法。当我运行这个地图时,不断地放大和缩小。我目前正在从我的活动中的onCreate调用它。我在这里做错了什么?我有一个Android应用程序,正在建设中使用Google Maps,当我尝试获取当前位置时,地图正在放大和缩小

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);    


     } 
    } 
+0

这不是因为您为不同的缩放级别移动和动画吗? – Moesio 2013-03-20 19:24:35

+0

虽然我并不感动。 – yams 2013-03-20 20:24:33

+0

哦,对不起,我以为你在map.moveCamera和map.animateCamera – Moesio 2013-03-21 01:19:31

回答

0

我发现,每0秒我问了一个位置更新为每requestLocationUpdates方法,只是我的一个错字。像往常一样,那是一件小事让我害怕。因此,而不是:

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); 

我应该有:

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 10, ll); 

与10000等效于十秒钟。一旦我改变了这一点,我就能够成功运行应用程序,并正确更新更新。

相关问题