0

我正在尝试使用 googlemaps 地理编码器检索地址..但是我只得到几个地址..因为我看到我的 javascript 在 10 个地址之后无法检索..下面是我的代码

function fetchData(lat,lng,type){   

    $('#placedata').empty();
    myLatlng = new google.maps.LatLng(parseFloat(lat), parseFloat(lng));
    map = new google.maps.Map(document.getElementById('map'), {
                    mapTypeId: google.maps.MapTypeId.ROADMAP,
                    center: myLatlng,
                    zoom: 10});
    var request = {location: myLatlng,radius: 50000,types: [type]};
    var service = new google.maps.places.PlacesService(map);
    service.search(request, callback);
  }

  function callback(results, status) {  

      for (var i = 0; i < results.length; i++) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {  
          createMarker(results[i]);     
        }       
    }
  }

  function createMarker(place) {
    place.geometry.location});

    var request = {reference: place.reference,};
    service = new google.maps.places.PlacesService(map);
    service.getDetails(request, detailsDisplay);

    function detailsDisplay(details, status) {      
        $('#placedata').append('<tr><td><a href='+details.url+'>'+details.name+'</a></td></tr>');

    }

}

正如我看到许多人有同样的问题..有没有办法或使用 setTimeout 函数并延迟请求所以我得到至少 20 个地址..任何帮助将不胜感激..谢谢

4

2 回答 2

4

该解决方案setTimeout用于防止OVER_QUERY_LIMIT

function createMarker(place) {
    //var placeLoc = place.geometry.location;
    //var marker = new google.maps.Marker({map: map,zIndex: 100,position: place.geometry.location});

    var request = {
        reference : place.reference,
    };

    service = new google.maps.places.PlacesService(map);

    service.getDetails(request, function(details, status) {
        if (status === google.maps.places.PlacesServiceStatus.OK) {
            $('#placedata').append('<tr><td><a href='+details.url+'>' + details.name + '</a></td></tr>');
        } else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
            setTimeout(function() {
                createMarker(place);
            }, 200);
        }
    });
}
于 2012-10-04T12:47:36.633 回答
-1

我有解决方案。

试试这个

if(pagination.hasNextPage){
pagination.nextPage();
}

if(pagination.b == null){
createMarker(place);
}

//不需要setTimeout。试试这个。这将对您有所帮助。

于 2013-09-03T12:01:52.860 回答