我正在添加一个触摸地图的制造商,并希望通过单击某个按钮来删除该标记,但该标记并未从地图中删除。这是我的代码
// Marker of end Point
Marker endPointMarker;
点击地图
@Override
public void onMapClick(LatLng point) {
// TODO Auto-generated method stub
double lat = point.latitude;
double lng = point.longitude;
// Add marker of destination point
try {
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(BookCabScreen.this);
if (lat != 0 || lng != 0) {
addresses = geocoder.getFromLocation(lat, lng, 1);
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
Log.d("TAG", "address = " + address + ", city =" + city
+ ", country = " + country);
endPointMarker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lng))
.title("Location").snippet("" + address));
markers.add(mMap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lng))
.title("Location").snippet("" + address)));
btnStartUp.setEnabled(true);
btnStopPoint.setEnabled(true);
mJbBookCab.setEndPointLat(lat);
mJbBookCab.setEndPointLng(lng);
} else {
Toast.makeText(BookCabScreen.this,
"latitude and longitude are null",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
点击按钮
if (endPointMarker != null) {
endPointMarker.remove();
endPointMarker = null;
}
但它没有从地图中删除?请帮忙