google.maps.places.Autocomplete 502 error

混江龙づ霸主 提交于 2019-12-14 03:05:15

问题


I am using the google.maps.places.Autocomplete API and this morning I was getting a 502 Bad Gateway error. It lasted about 10 minutes and started working again. I assume this had to do with the service being unavailable.

I was wondering how I can error handle when this happens. My (javascript) autocomplete code looks like this:

$('#StartAddress').change(function () {
    google.maps.event.trigger(startAutocomplete, 'place_changed');
    return false;
});


var source, destination;
var directionsDisplay;
var directionsService;
if (typeof google === 'object' && typeof google.maps === 'object') {
    directionsService = new google.maps.DirectionsService();

    // set up places autocomplete
    var start = document.getElementById('StartAddress');
    var startAutocomplete = new google.maps.places.Autocomplete(start);

    var end = document.getElementById('EndAddress');
    var endAutocomplete = new google.maps.places.Autocomplete(end);

    // add the places auto complete listener for when the values change
    startAutocomplete.addListener('place_changed', function () {
        var startAddress = $('#StartAddress').val();
        var endAddress = $('#EndAddress').val();
        if (endAddress && startAddress) {

            GetRoute(startAddress, endAddress, false);
        }
    });

    endAutocomplete.addListener('place_changed', function () {
        var endAddress = $('#EndAddress').val();
        var startAddress = $('#StartAddress').val();
        if (endAddress && startAddress) {

            GetRoute(startAddress, endAddress, false);
        }
    });
    directionsDisplay = new google.maps.DirectionsRenderer({ 'draggable': false });
}

The GetRoute(startAddress, endAddress, false) function is a call to the google.maps.Map and that works fine. It was only the autocomplete service that was down.

Also, is it possible this error occurred because I am using the developer key instead of production? Like the googles dev environment is much more resource limited?


回答1:


The service was down this time. Try again now.



来源:https://stackoverflow.com/questions/47143691/google-maps-places-autocomplete-502-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!