Google Places API仅针对某些地方返回ZERO_RESULTS

时间:2016-12-21 12:32:12

标签: google-maps-api-3 google-places-api

对于某些地方,如机场或火车站,我的代码工作正常,输入完整的地址,如“16 CoursduMédoc,Bordeaux,France”,它也可以正常工作,但对于大多数地方,它不起作用,我得到ZERO_RESULTS状态。

我很困惑,无法找到问题所在。

以下是代码:

var drop = document.getElementById('destination');
var drop_autocomplete = new google.maps.places.Autocomplete(drop);
 drop_autocomplete.bindTo('bounds', map);
     drop_autocomplete.addListener('place_changed', function() {
                                            var placea = drop_autocomplete.getPlace();
                                            nom_arrivee = placea.name;
                                            arrivee_formulaire = placea.formatted_address;
                                   vicina = placea.vicinity;
                                   latitudeArrivee = placea.geometry.location.lat();
                                   longitudeArrivee = placea.geometry.location.lng();
                                            });
                   }
        google.maps.event.addDomListener(window, 'load', initialize);

function doCalculation()
{
var cartypes=document.getElementById('cartypes').value;
var address = document.getElementById('source').value;
var destination = document.getElementById('destination').value;
if(cartypes.trim()=='')
{
    alert("Please Select Car Type. if Cartype is empty, then you need to inser first from admin side.");
    return false;
}
if(address.trim() == '') {
    alert("Please Enter Pickup Address");
    source = '';
    return false;
}
if(destination.trim() == '') {
    alert("Please Enter Drop Off Address");
    destination = '';
    return false;
}
if (first_time)
 {
     jQuery("#map_canvas").show(600);
     setTimeout(sourceAddress, 800);
     first_time = false;
 } else {
     sourceAddress();
 }
}
function sourceAddress() {
clear();
jQuery("#map_canvas").show(800);
waypoints = new Array();
var address = document.getElementById('source').value;
var destination = document.getElementById('destination').value;
geocoder.geocode({'address': address}, function(results, status) {
    console.log(results);
    if (status == google.maps.GeocoderStatus.OK) {
        var lat = document.getElementById("latitude").value = results[0].geometry.location.lat();
        var lng = document.getElementById("longitude").value = results[0].geometry.location.lng();
        var lng = document.getElementById("dest_latitude").value = results[0].geometry.location.lng();
        var lng = document.getElementById("dest_longitude").value = results[0].geometry.location.lng();

        var marker = new google.maps.Marker({
            map: map,
            icon: home,
            position: results[0].geometry.location

        });
        markers[count_markers++] = marker;
        destinationAddress();

    }
    else {
        alert('Result was not successful for the following reason: ' + status);
    }
});
}
function destinationAddress() {
var source = document.getElementById('source').value;
var address = document.getElementById('destination').value;
var request = {
    origin: source,
    destination: address,
    waypoints: waypoints,
    travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
    }
});
geocoder.geocode({'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
        var lat = document.getElementById("dest_latitude").value = results[0].geometry.location.lat();
        var lng = document.getElementById("dest_longitude").value = results[0].geometry.location.lng();

        var marker = new google.maps.Marker({
            map: map,
            icon: taxi,
            position: results[0].geometry.location
        });
        markers[count_markers] = marker;
        var picLatLng = new google.maps.LatLng(jQuery('#latitude').val(),         jQuery('#longitude').val());
        var dropLatLng = new google.maps.LatLng(jQuery('#dest_latitude').val(), jQuery('#dest_longitude').val());
        markerBounds.extend(picLatLng);
        markerBounds.extend(dropLatLng);
        map.fitBounds(markerBounds);
        calc();

    } else {
        alert('Geocode was not successful for the following reason: ' + status);
    }
});
}

0 个答案:

没有答案