Google Map Api Invalid Value Error

后端 未结 2 1341
挽巷
挽巷 2021-01-22 12:55

I have created the following code using Google Maps API that should make a direction line on Google Maps between two given addresses. My Code is:

2条回答
  •  星月不相逢
    2021-01-22 13:59

    When you call the function calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB); the positions pointAand pointB are undefined because they are the result of the asyncronous call of geocoder.geocode.

    Move the calculateAndDisplayRoute function call after you've obtained a result from geocoder.geocode

      geocoder.geocode({
        'address': document.getElementById('addressTo').value
      }, function(results, status) {
        var location = results[0].geometry.location;
        poi
    
    if (status == google.maps.GeocoderStatus.OK) {
        calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB);
        }
    

    Since you're sending two geocoding requests you will need to wait for the geocoder status for each request.

提交回复
热议问题