如何移动单个标记在谷歌地图Android版V2? [英] how to move single marker in google maps v2 android?

查看:220
本文介绍了如何移动单个标记在谷歌地图Android版V2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加入了很多标记在谷歌地图V2的android,我用一个哈希表来存储每个标记的id,结果我能customwindow等等,但问题是我要删除/移动标记根据id。

I added a lot of markers in google maps v2 android, I use a hashtable to store the id of each marker, and the results I could make customwindow and so on, but the problem is I want to delete / move the marker based on the id.

这是我的code创建一个标记,我解析来自JSON数据

This my code to create a marker, I parse data from json

private Hashtable<String, String> markers;
markers = new Hashtable<String, String>();

private void createMarker(String result) throws JSONException{

    jObject = new JSONObject(result);
    JSONArray menuitemArray = jObject.getJSONArray("data");
    for (int i = 0; i < menuitemArray.length(); i++) {
        id=menuitemArray.getJSONObject(i).getString("id").trim();
        ttl=menuitemArray.getJSONObject(i).getString("user").trim();
        snip=menuitemArray.getJSONObject(i).getString("desc").trim();
        lat=menuitemArray.getJSONObject(i).getString("latitude").trim();
        lng=menuitemArray.getJSONObject(i).getString("longitude").trim();

        Marker mk = googleMap.addMarker(new MarkerOptions()
        .position(new LatLng(Double.parseDouble(lat),Double.parseDouble(lng)))
        .title(ttl)
        .snippet(snipq)
        .icon(BitmapDescriptorFactory.fromBitmap(BmFinal)));

        markers.put(mk.getId(), id); //here i add info to hastable marker

    }
}

我想在这一空白移动标记

I want to move marker in this void

private void moveMarker(String Id){
    //what should i do in here ???
}

如何我做到这一点?感谢..

how to I achieve that? thanks..

推荐答案

我不能发表评论,但你可能想试试这个;首先删除标记,然后在您需要的新的地方,但具有相同特征的创建另一个。结果
如上例(只要你的想法):

I can't comment but you might want to try this; Remove the marker first then create another in the new place you want but with the same characteristics.
As example (Just so you get the idea):

public void moveMarker(String Id) {    

   markers.get(Id).remove(); // this removes the marker

   Marker newMk = googleMap.googleMap.addMarker(new MarkerOptions()
        .position(new LatLng(Double.parseDouble(newlat),Double.parseDouble(newlng))) // new coordonates
        .title(ttl)
        .snippet(snipq)
        .icon(BitmapDescriptorFactory.fromBitmap(BmFinal))); // same details

        // now add to your map & collection
        markers.put(newMk.getId(), Id);
}

这篇关于如何移动单个标记在谷歌地图Android版V2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆