我想使用gmaps.js在全球50多个地址之间循环,并在地图上添加标记。多亏了对另一个问题的回答,我以为我已经解决了。
gmaps.js - loop through elements and add markers
简言之,使用准确的答案(现场示例http://jsfiddle.net/w8bvR/3/)。
脚本端

    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端
    <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>

但是由于某些原因,当我从mysql获取地址viva PHP并创建50+时,它只添加了11个标记来映射,不管我创建的mysql的顺序或选择是什么我有点搞不懂为什么它会把自己限制在11个,因为googleapi声称至少在这个级别上没有限制。感谢任何帮助。
鉴于我是从mysql/php中获取数据的,我确信还有一种更优雅的方法,但这两种方法都不是专家。

最佳答案

问题是代码没有检查OVER_QUERY_LIMIT错误并进行适当的处理。如果不处理这种情况,您将从地理编码服务(如您所看到的)得到大约10个响应。

关于php - gmaps.js遍历地址并添加标记,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14309438/

10-10 09:36
查看更多