2016-04-10 10 views
0

. Harita güncellendiğinde her zaman yeni bir işaretçi ekler. Bu, aynı konumdaki çeşitli işaretçileri bırakır.Google Haritalar, haritalamamdaki sorunların giderilmesi için her defasında yeni bir işaretçi eklemeye devam ediyor

Bu, yol tarifi gibi başka içerik eklemeden önce sıralamak istiyorum.

public void onMapReady(GoogleMap googleMap) { 
    mMap = googleMap; 


    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 
     // TODO: Consider calling 
     return;// 
    } 
    mMap.setMyLocationEnabled(true); // shows location on map 
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
    listener = new LocationUpdateListener(); 
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener); 
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener); 
} 
private void handleNewLocation(Location location) { 
    Log.d(TAG, location.toString()); 

    double currentLatitude = location.getLatitude(); 
    double currentLongitude = location.getLongitude(); 

    LatLng latLng = new LatLng(currentLatitude, currentLongitude); 

    MarkerOptions options = new MarkerOptions() // This adds in a marker 
      .position(latLng) 
      .title("Reverse Geo Toast here ???"); // when marker clicked, it will display you are here 
    mMap.addMarker(options); 
    // mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 
    float zoomLevel = (float) 10; //This zooms into the marker 
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomLevel)); 
} 
+0

Böylelikle mevcut işaretleyici konumunu güncellemek istiyorum yerine? – antonio

cevap

1

Sen kullanarak mevcut işaretleyici (Reference) pozisyonunu güncelleyebilirsiniz: yenisini eklemenin

private Marker marker; 

// ... 

private void handleNewLocation(Location location) { 
    Log.d(TAG, location.toString()); 

    double currentLatitude = location.getLatitude(); 
    double currentLongitude = location.getLongitude(); 

    LatLng latLng = new LatLng(currentLatitude, currentLongitude); 

    if (marker == null) { 
     MarkerOptions options = new MarkerOptions() // This adds in a marker 
       .position(latLng) 
       .title("Reverse Geo Toast here ???"); // when marker clicked, it will display you are here 
     marker = mMap.addMarker(options); 
    } 
    else { 
     marker.setPosition(latLng); 
    } 
    // mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 
    float zoomLevel = (float) 10; //This zooms into the marker 
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoomLevel)); 
} 
İlgili konular