Best solution for too many pins on google maps

亡梦爱人 提交于 2020-01-13 12:12:35

问题


Here is my Google Maps "Setup"

  • I read from database the locations of all markers (under 300) - sent those into javascript as Json
  • On javascript i parse the json, look trough marker array and create a new google.maps.Marker. For each marker i add an event for clicl that will open a infobox (infoBox.js) with a main picture and some custom details. After that i create clusters( using MarkerClusterer) and everything works well (at least for 3-400 markers)

I want to expand and display up to 10k of markers ( using MarkerClusterer).What will be the best approach ?

I was thinking into writing all markers data into a file(as javascript array or xml) and have javascript reading from there since will not be practical to query the database for 10k locations. Do you advise otherwise ?

Should i use the same looping trough array and put one marker at a time ? I looked over kml layers but it seems i cannot navigate trough markers (i have a prev/next location feature) and i may not be able to use the infobox.js ?

Any advice ?


回答1:


As @geocodezip mentioned have a look at that doc, and rather than looking at the Cluster solution take a look at the Viewport Marker Management section.

Provided your database supports geospatial queries, you can make a request to return only markers within a given bounds once the map is idle.

google.maps.event.addListener(map, 'idle', function(){
    var bounds = map.getBounds(); //returns an object with the NorthEast and SouthWest LatLng points of the bounds

    //make the AJAX request passing in your `bounds`

    /*in the AJAX callback remove the current markers from the map and the cluster object, 
    and add the new ones along with their event handlers and re-add to the cluster object as well*/

});


来源:https://stackoverflow.com/questions/20431170/best-solution-for-too-many-pins-on-google-maps

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