在数据库更新时更新标记位置 Android

Update marker position on database update Android

我在 MySQL 数据库中保存了一组纬度和经度。我使用以下方法将它们绘制在我的地图上:

 for (int i = 0; i < jArray.length(); i++) {
            JSONObject json_data = jArray.getJSONObject(i);
                    double lat = json_data.getDouble("lat");
                    double lng= json_data.getDouble("long");
            MyItem offsetItem = new MyItem(lat, lng);
            mClusterManager.addItem(offsetItem);

(我使用 Async Task 来获取位置并保留了一个 Timer 来继续调用该 Task) 这些位置对应于特定的车辆,因此我计划使用此 link

添加

Showing custom InfoWindow for Android Maps Utility Library for Android.

我的问题是,一旦特定条目的位置在数据库中更新,我需要找到该标记,并且 move/animate 标记到新的新位置。

我怎样才能做到这一点?

创建标记时,您需要将它们存储在某个地方,例如数组或列表。您需要以将标记与位置相关联的方式标识每个标记。标记有 ID property that is unique across the map, so you can try using that. Alternatively, you can use the Title or content in the InfoWindow to differentiate the markers. You can also try using the position the marker assuming you can retrieve the "old" position before you update it. With whatever method you use, once you get a match, you can then update the marker position with setPosition.

还有一些 third party libraries 可供您检索标记。