admin管理员组文章数量:1402949
I'm using google maps for a web site development. There are a lot of markers in my database. I want to load markers that are in the area that is shown in the current map. And when the zooming changes the number of markers should also adjust accordingly. What's the best approach? Thanks in advance!
I'm using google maps for a web site development. There are a lot of markers in my database. I want to load markers that are in the area that is shown in the current map. And when the zooming changes the number of markers should also adjust accordingly. What's the best approach? Thanks in advance!
Share Improve this question asked Jun 11, 2016 at 16:00 Danuja JayawardhanaDanuja Jayawardhana 331 silver badge4 bronze badges 1- Why would you need to remove a marker if it's not in view? I think you need to explain the end goal of this. – DBS Commented Jun 11, 2016 at 16:31
2 Answers
Reset to default 5Use the bound
aNord = this.map.getBounds().getNorthEast().lat();
aEst = this.map.getBounds().getNorthEast().lng();
aSud = this.map.getBounds().getSouthWest().lat();
aOvest = this.map.getBounds().getSouthWest().lng();
for filter (server side ) data from database (in this case php)
"select lat, lng
from your_table
where lat >= $minLat
AND lat <= $maxLat
AND lng <= $maxLng
AND lng >= $minLng";
You can also use bounds_changed function to add or remove data when user changes zoom level or pan the map.
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: {lat:41.082774, lng: 28.86821},
disableDefaultUI: true
});
google.maps.event.addListener(map, 'bounds_changed', function() {
aNord = map.getBounds().getNorthEast().lat();
aEst = map.getBounds().getNorthEast().lng();
aSud = map.getBounds().getSouthWest().lat();
aOvest = map.getBounds().getSouthWest().lng();
});
本文标签: javascriptgoogle maps load only markers in the displayed areaStack Overflow
版权声明:本文标题:javascript - google maps load only markers in the displayed area - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744349984a2601990.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论