谷歌地图上太多针脚的最佳解决方案 [英] Best solution for too many pins on google maps

查看:128
本文介绍了谷歌地图上太多针脚的最佳解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的谷歌地图设置


  • 我从数据库中读取所有标记的位置(低于300) - 将它们发送到javascript as Json

  • 在javascript上解析json,查看槽标记数组并创建一个新的google.maps.Marker。对于每个标记我添加一个事件clicl将打开一个信息框(infoBox.js)与主图片和一些自定义的细节。之后,我创建群集(使用MarkerClusterer),一切正常(至少3-400个标记)显示多达10k的标记(使用MarkerClusterer)。什么是最好的方法?



    我正在考虑将所有标记数据写入文件(如javascript数组或xml ),并从那里读取JavaScript,因为查询10k位置的数据库不太实际。你是否建议不然?



    我应该使用相同的循环槽阵列并一次放置一个标记吗?
    我查看了kml图层,但似乎我无法导航槽标记(我有prev / next位置功能),我可能无法使用infobox.js?

    任何建议?

    解决方案

    由于@geocodezip提到了这个文档,而不是看着群集解决方案查看视口标记管理部分。



    如果您的数据库支持地理空间查询,那么一旦地图为 idle ,您就可以请求只返回给定范围内的标记。 / p>

      google.maps.event.addListener(map,'idle',function(){
    var bounds = map。 getBounds(); //返回一个包含边界的NorthEast和SouthWest LatLng点的对象

    //使AJAX请求通过你的`bounds`

    / * in AJAX回调删除th从映射和集群对象获取当前标记
    ,并添加新的以及它们的事件处理程序并重新添加到集群对象* /

    });


    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 ?

    解决方案

    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*/
    
    });
    

    这篇关于谷歌地图上太多针脚的最佳解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆