本文介绍了获取的地图标记其在谷歌地图V2 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

基本上添加标记到地图时,它返回新的标记,你可以从它得到的标记ID像这样

basically when adding a marker to the map it returns the new marker and you can gets the marker id from it like so

Marker m = map.addMarker(new MarkerOptions()
                            .position(new LatLng(lat,lon)));
String id = m.getId();

有没有办法让一个标记的编号,如果有很多标记,你只是想删除一个?

is there a way to get a marker by its id if there are many markers and you just want to delete one?

推荐答案

的问题是,该标记ID是程序自动生成的,不能用于单独跟踪标记。许多策略被提出的工作解决这个问题。其中之一是为<一个href="http://discgolfsoftware.word$p$pss.com/2012/12/06/hiding-and-showing-on-screen-markers-with-google-maps-android-api-v2/">use哈希映射跟踪标记,然后使用你选择的关键找个上特有的标记,将其删除。另一个想法是重载标记领域里,如片断之一,然后自己添加一键。例如,如果你做一个新的标记(使用谷歌的例子code)你可以把自己的钥匙串入段字段

The problem is that the marker id is generated automaticlly and cannot be used for tracking the markers individually. A number of strategies have been proposed work around this. One would be to use a hash map to track markers and then use a key you choose to find a speific marker and remove it. Another idea is to overload one of the marker fields, like snippet, and then add a key yourself. For example, if you were making a new marker (using the google example code) you could put your own key string into the snippet field

mMap.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title("Melbourne")
.snippet(KEY + "Population: 4,137,400"));

之后,你可以使用retrive该键

Later you could retrive that key using

String s = marker.getSnippet()
String key = s.substring(start, end)

和然后使用条件删除特定的标记物,如果它是一个匹配。根据whatyou需要做的一种方法我更容易和更有效的比其他。

and then use a conditional to remove a specific marker if it is a match. Depending on whatyou need to do one approach my be easier and more efficient than another.

这篇关于获取的地图标记其在谷歌地图V2 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:49