Multiple markers Google Map API v3 from array of addresses and avoid OVER_QUERY_LIMIT while geocoding on pageLoad

前端 未结 3 1828
误落风尘
误落风尘 2020-11-27 10:47

I have to implement the multiple markers functionality from array of addresses. The string of addresses are being fetched from the database.

My array of addresses lo

3条回答
  •  -上瘾入骨i
    2020-11-27 11:44

    Regardless of your situation, heres a working demo that creates markers on the map based on an array of addresses.

    http://jsfiddle.net/P2QhE/

    Javascript code embedded aswell:

    $(document).ready(function () {
        var map;
        var elevator;
        var myOptions = {
            zoom: 1,
            center: new google.maps.LatLng(0, 0),
            mapTypeId: 'terrain'
        };
        map = new google.maps.Map($('#map_canvas')[0], myOptions);
    
        var addresses = ['Norway', 'Africa', 'Asia','North America','South America'];
    
        for (var x = 0; x < addresses.length; x++) {
            $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address='+addresses[x]+'&sensor=false', null, function (data) {
                var p = data.results[0].geometry.location
                var latlng = new google.maps.LatLng(p.lat, p.lng);
                new google.maps.Marker({
                    position: latlng,
                    map: map
                });
    
            });
        }
    
    }); 
    

提交回复
热议问题