Load only markers surrounding my location Google Map v2 Android

南楼画角 提交于 2019-12-09 06:52:26
MaciejGórski

How do I set this up and only add my markers per this method?

Google Maps Extension's

map.setClustering(new ClusteringSettings().enabled(false).addMarkersDynamically(true));

method does exactly that. Adds only Markers in visible region to the map. All markers outside of it are kept by Extensions lib, but no interprocess communication is made in order to put them on the map. They will be added when user scrolls to show different region.

If you think it's something wrong with the map, first thing I would try would be using default marker icon or creating only one BitmapDescriptor for all Markers:

BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.snotel_marker));
for (int i = 0; i < nsize; i++) {
    // ...
    m = map.addMarker(new MarkerOptions()
                        .position(new LatLng(latitude, longitude))
                        .title(title)
                        .icon(icon);
    // ...
}

This should solve OutOfMemoryError issues.


Other than that, you don't want to call setOnInfoWindowClickListener in a loop. Once is more than enough.
And one more thing: if that's all data you want to keep, you may use MarkerOptions.snippet and Marker.getSnippet for your String desc. No need to keep it all in Map<Marker, MapMarkers> data structure. If you want to keep additional data beside two Strings and LatLng, I suggest using MarkerOptions.data(marks) (since 1.6) or Marker.setData(marks) in Extensions lib. To read it later in OnInfoWindowClickListener callback:

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