0

我想跟踪地图上的标记。单击特定标记时,我需要显示有关该标记的信息。

我正在使用一个 HashMap 变量来跟踪添加到地图上的标记。

for (int i = 0; i <= PropertyStub.size() - 1; i++) {
        final LatLng MeanLatLng = new LatLng(PropertyStub.get(i).Latitude,
                PropertyStub.get(i).Longitude);

        if (!visibleMarkers.containsKey(PropertyStub.get(i).PropertyID)) {
            visibleMarkers
                    .put(PropertyStub.get(i).PropertyID,
                            this.map.addMarker(new MarkerOptions()
                                    .position(MeanLatLng)
                                    .title("Property")

                                    .icon(BitmapDescriptorFactory
                                            .fromResource(R.drawable.pink_outside_marker))));

        }
    }

当我单击特定标记时,我需要该单击标记的 PropertyID 值,

 public boolean onMarkerClick(Marker marker) {

    marker.showInfoWindow();
    tvPropertyID.setText("" + visibleMarkers.get(marker));

    return true;
}

但我得到“visibleMarkers.get(marker)”为空。信息窗口上显示一个空字符串。我在哪里做错了?请纠正我。请给我一个有用的链接。

提前致谢!!

4

1 回答 1

1

"visibleMarkers.get(marker)" is null because your keys are Strings, not Markers.

Here's where you populate the map:

visibleMarkers.put(PropertyStub.get(i).PropertyID, ...);

Assuming PropertyID is a String, then of course visibleMarkers.get(marker) will be null since you are not getting the right key.

Sounds like you need a HashMap of Markers->Strings since you appear to need to lookup the String value for a given Marker. Change your data structure to HashMap<Marker,String> and take it from there.

于 2013-06-18T08:25:12.013 回答