List list always return list size() =1

2019-09-11 07:44发布

Here I am adding marker on map:

hereMap.addMapObject(new MapMarker(new GeoCoordinate(lat,lng), myImage)
       .setTitle("marker"+geoCounter)
       .setDescription(" \nLatitude :" +lati+  "\nLongitude : "+ lng));

adding lat lng with array list of lat lng but when I add the marker with the help of:

@Override
public void onLocationChanged(Location location) {...}

List<ViewObject> list gives me the exact size of the added marker.

In this case, I get lat long with:

location.getLatitude()
location.getLongitude()

Here are the map markers on map:

Image1

Here I get size like this:

Image2

1条回答
甜甜的少女心
2楼-- · 2019-09-11 08:18

Seems

public abstract boolean onMapObjectsSelected (java.util.List <ViewObject> objects)

A callback indicating that at least one ViewObject has been selected as a result of a user tapping on the map. So objects has only selected markers. For get access to all markers on map You should save the resulting Marker object in a collection (for example ArrayList<MapMarker>) of your choice after you call addMarker(), like in this answer. For example:

ArrayList<MapMarker> mMarkersList = new ArrayList();
...
MapMarker marker = new MapMarker(new GeoCoordinate(lat,lng), myImage)
            .setTitle("marker"+geoCounter)
            .setDescription(" \nLatitude :" +lati+  "\nLongitude : "+ lng)
mMarkersList.add(marker);
hereMap.addMapObject(marker);

then get it from mMarkersList:

MapMarker marker = mMarkersList.get(<number_of_marker>)
查看更多
登录 后发表回答