首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在谷歌地图v2中删除以前的标记并添加新标记

在谷歌地图v2中删除以前的标记并添加新标记
EN

Stack Overflow用户
提问于 2013-06-29 19:43:05
回答 6查看 51.5K关注 0票数 20

我想在地图上任何地方长时间单击后删除当前标记,并在该点重新创建一个新标记。我已经清除了谷歌地图上长时间点击地图和新的标记被创建,但以前的标记也显示。

我的代码是:

代码语言:javascript
复制
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;

}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17379807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档