Ich möchte eine Markierung löschen, die es multipliziert wegen der Position ändert Ich habe versucht map.clear(), aber es löscht auch die Polylinie, die ich zeichnete und marker.remove, aber es zeigt nicht mehr Ich möchte auch einen anderen Marker implementieren, der mir einen GPS-Standort zeigt und den Abstand zwischen diesen Markern ermittelt. Weiß jemand, wie ich das machen kann? Vielen Dank!mehrere Marker auf Benutzerstandort Android
Dies ist mein Code
package com.example.alejandro.integradora2;
import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
public class Route extends AppCompatActivity implements OnMapReadyCallback {
public GoogleMap mMap;
Marker marker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
setUpMapIfNeeded();
}
//here is the marker that keeps multiplying
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
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
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
mMap.setMyLocationEnabled(true);
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location arg0) {
// TODO Auto-generated method stub
marker= mMap.addMarker(new MarkerOptions().position(new LatLng(arg0.getLatitude(), arg0.getLongitude())).title("Tu Ubicacion Actual"));
}
});
}
}
}
public void onMapReady(GoogleMap map) {
map=mMap;
// Add a marker in Sydney and move the camera
LatLng inicio = new LatLng(23.979804, -104.641936);
LatLng fin = new LatLng(24.024227, -104.664647);
mMap.addMarker(new MarkerOptions().position(inicio).title("Inicio Ruta").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
mMap.addMarker(new MarkerOptions().position(fin).title("Fin Ruta"));
//mMap.animateCamera(CameraUpdateFactory.zoomTo(10));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(23.979804, -104.641936), 12));
PolylineOptions RutaIda = new PolylineOptions()
.add(new LatLng(23.979804, -104.641936),new LatLng(23.986028, -104.663826),new LatLng(23.986337, -104.664357),new LatLng(23.996928, -104.662372),new LatLng(23.997051, -104.662469),
new LatLng(23.998414, -104.662179),new LatLng(24.007054, -104.662335),new LatLng(24.008568, -104.662292),new LatLng(24.015409, -104.663338),new LatLng(24.017710, -104.663729),
new LatLng(24.019288, -104.664051),new LatLng(24.023110, -104.663981),new LatLng(24.024296, -104.664153),new LatLng(24.024227, -104.664647)
)
.width(5)
.color(Color.RED);
Polyline polyline = mMap.addPolyline(RutaIda);
PolylineOptions RutaVuelta = new PolylineOptions()
.add(new LatLng(24.024227, -104.664647),new LatLng(24.023497, -104.669067),new LatLng(24.021361, -104.668826),new LatLng(24.021430, -104.668161),new LatLng(24.019950, -104.667893),
new LatLng(24.019666, -104.665200),new LatLng(24.019490, -104.664937),new LatLng(24.019431, -104.664524),new LatLng(24.018319, -104.664030),new LatLng(24.016864, -104.664062),
new LatLng(24.015170, -104.663458),new LatLng(24.008048, -104.662445),new LatLng(23.998369, -104.662447),new LatLng(23.993684, -104.663177),new LatLng(23.986396, -104.664572),
new LatLng(23.986318, -104.664277),new LatLng(23.986053, -104.663848),new LatLng(23.979804, -104.641936))
.width(8)
.color(Color.parseColor("#802E2EFE"));
//.color(Color.BLUE);
Polyline polylinevenida = mMap.addPolyline(RutaVuelta);
}
}
Es sieht nicht wie dieser Code ruft marker.remove() – nasch
Ich löschte es, weil es die Markierung von –