duanmu3049 2013-01-13 23:24
浏览 39
已采纳

gmaps.js遍历地址并添加标记

I'd like to use gmaps.js to loop through 50+ addressed worldwide and add markers to a map. Thanks to a great answer to another question I thought I had it solved.

gmaps.js - loop through elements and add markers

In short using the exact answer there (live example http://jsfiddle.net/w8bvR/3/).

SCRIPT SIDE

    var map = new GMaps({
    div: '#mapCanvas',
    lat: 0,
    lng: 52,
    zoom: 13,
    width: '600px',
    height: '400px'
});

var popupTemplate = '<div class="popupText"><h3>%1</h3><p>%2</p></div>';
var location = $('#location').text();

$('.blist p').find('br').replaceWith(', ');

$(".blist").each(function() {
    var title = $(this).find("h3").text();
    var address = $(this).find("p.address").text();
    GMaps.geocode({
        address: address,
        callback: function(results, status) {
            if (status == 'OK') {
                var latlng = results[0].geometry.location;
                map.setCenter(latlng.lat(), latlng.lng());
                map.addMarker({
                    lat: latlng.lat(),
                    lng: latlng.lng(),
                    title: title,
                    infoWindow: {
                        content: popupTemplate.replace('%1',title).replace('%2',address)
                    }
                });
            }
        }
    });
});

HTML SIDE

    <div id="mapCanvas"></div>
<h1 id="location">Phuket, Thailand</h1>

<div class="blist">
    <h3>APK Resort</h3>
    <p class="address">95 Ratchapratanusorn road<br>Kathu<br>Patong Beach 83150<br>Phuket<br></p>
</div>

<div class="blist">
    <h3>Patong Bay House</h3>
    <p class="address">160/5 Phungmuang Sai kor Rd<br>Phuket<br>Patong Beach 83150<br>Kathu<br></p>
</div>

<div class="blist">
    <h3>Bel Aire Resort</h3>
    <p class="adress">59/1-3 Sainamyen Rd Patong Kathu<br>Phuket<br>Patong Beach 8310<br>T<br></p>
</div>

However for some reason when I fetch the addresses viva PHP from my mysql and create the 50+ 's it only add 11 markers to map no matter what order or select from the mysql that I create. I'm sort of lost to why it would limit itself to 11 as googles API claims there are no limits at least on that level. Any help appreciated.

Seeing I'm fetching from mysql/php I'm sure there are a more elegant way as well, but no expert on either.

  • 写回答

1条回答 默认 最新

  • dtpd58676 2013-01-14 00:07
    关注

    The issue is the code doesn't check for the OVER_QUERY_LIMIT error and handle it appropriately. Without handling that case you will get approximately 10 responses from the Geocoding Service (as you are seeing).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题