List<ViewObject> list always return list size() =1 Here map

耗尽温柔 提交于 2019-12-12 06:29:15

问题


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:

Here I get size like this:


回答1:


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>)


来源:https://stackoverflow.com/questions/40585600/listviewobject-list-always-return-list-size-1-here-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!