我正在尝试在用户位置显示标记并删除之前的标记。我尝试了类似这样的东西,但它没有用。
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Toast.makeText(getActivity(),
String.valueOf(location.getLatitude()),Toast.LENGTH_SHORT).show();
Marker playermarker = null;
if (playermarker!=null) {
playermarker.remove();
playermarker=null;
}
if (playermarker==null) {
playermarker = googleMap.addMarker(new
MarkerOptions().position(new
LatLng(location.getLatitude(),location.getLongitude())));
}
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
答案 0 :(得分:0)
使用此
onLocationChanged{
if (currLocationMarker != null) {
currLocationMarker.remove();
}
latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position.......");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
currLocationMarker = mMap.addMarker(markerOptions);
}
自定义标记选择图像格式可绘制文件夹
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));