已经尝试了一段时间来解决我的地图问题,这是标记。每次地图更新时,都会添加一个新标记。这会在同一位置留下几个标记。
我希望在添加其他内容(如路线)之前对其进行排序。
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));
}