지도를 아무 데나 클릭 한 후 현재 마커를 제거하고 그 지점에서 새 마커를 다시 만들고 싶습니다. 지도를 길게 클릭하면 Google지도가 지워지고 새 마커가 만들어 지지만 이전 마커도 표시됩니다.이전 마커를 제거하고 Google 마커 v2에 새 마커를 추가하십시오.
내 코드는 다음과 같습니다
이public class EditLocation extends Fragment {
View v;
Context c;
GoogleMap MAP;
Button back;
int loc;
String lat;
boolean isTapped = true;
public EditLocation(Context c, int location, String latitude) {
// TODO Auto-generated constructor stub
this.c = c;
this.loc = location;
this.lat = latitude;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.map, container, false);
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(c);
if (status != ConnectionResult.SUCCESS) {
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status,
(Activity) c, requestCode);
dialog.show();
} else {
FragmentManager myFM = ((FragmentActivity) c)
.getSupportFragmentManager();
final SupportMapFragment myMAPF = (SupportMapFragment) myFM
.findFragmentById(R.id.fragmentmap);
MAP = myMAPF.getMap();
MAP.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) c
.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
final Location location = locationManager
.getLastKnownLocation(provider);
final LatLng currentPosition = new LatLng(location.getLatitude(),
location.getLongitude());
MAP.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
// TODO Auto-generated method stub
MAP.addMarker(new MarkerOptions()
.position(currentPosition)
.snippet(
"Lat:" + location.getLatitude() + "Lng:"
+ location.getLongitude())
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
.title("ME"));
Log.e("lat", "" + point);
}
});
MAP.setOnMapLongClickListener(new OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng point) {
// TODO Auto-generated method stub
// isTapped = false;
MAP.clear();
MAP.addMarker(new MarkerOptions().position(point)
.title(point.toString()));
}
});
}
return v;
}
새로운 마커는 길게 클릭 한 후에 생성되지만 이전 마커는 맵에서 탭한 후 다시 제거되지 않지만 제거하려면 마커를 클릭하십시오. –
예 ... 잘 작동하지만 작은 문제는 새로운 마커가 생성되었지만지도를 터치 한 후 자동으로 새 마커가 제거되고 현재 마커에 이전 마커가 표시된 후 긴 문제입니다. –
지도에'onClick'과'onLongClick'을 모두 추가했습니다. 두 가지 모두에서 마커를 추가했습니다. 따라서지도를 클릭하거나 길게 클릭 할 때마다 이전 마커를 지우는 새로운 마커가 배치됩니다. –