Bradley
Bradley

Reputation: 2998

Google directions placeId and string in request uses placeId only in result

I have a bunch of stored addresses for routes in my application, but started using autocomplete place_id's for new requests. If an address is modified in the autocomplete field ('place_changed'), I have a scenario where I submit a request with a place_id and a string.

I didn't see anything that suggests this is not allowed in the docs, but when the results are returned, it appears to only use the place_id provided for both the the origin and destination.

You can replicate it below. Something I'm doing wrong?

var directionsService = new google.maps.DirectionsService();

var routeRequest = {
    avoidHighways: false,
    avoidTolls: false,
    destination: "19170 Geyserville Ave, Geyserville, CA 95441, USA",
    optimizeWaypoints: false,
    origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
    provideRouteAlternatives: false,
    travelMode: "DRIVING",
    waypoints: []
}


directionsService.route(routeRequest, function( result, status ) {
    console.log(result);
    console.log(status);
});

The above yields:

result.routes[0].legs[0].startAddress = "Best Western Dry Creek Inn, 198 Dry Creek Rd, Healdsburg, CA 95448, USA"

result.routes[0].legs[0].endAddress = "Best Western Dry Creek Inn, 198 Dry Creek Rd, Healdsburg, CA 95448, USA"

Upvotes: 2

Views: 1306

Answers (1)

geocodezip
geocodezip

Reputation: 161334

This looks like a bug in the API. Using a LatLng or a placeId with as the destination works, but using an address or a "place" query does not.

Issue in the issue tracker

These don't work:

var routeRequest = {
    origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
    destination: {query: "19170 Geyserville Ave, Geyserville, CA 95441, USA"},
    travelMode: "DRIVING"
}

  var routeRequest1 = {
    origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
    destination: "19170 Geyserville Ave, Geyserville, CA 95441, USA",
    travelMode: "DRIVING"
}

These do:

var routeRequest2 = {
    origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
    destination: {location: {lat:38.679366,lng:-122.872864}},
    travelMode: "DRIVING"
}

var routeRequest3 = {
    origin: {placeId: "ChIJs2LmmbgQhIARMlmj6BLNK_I"},
    destination: new google.maps.LatLng(38.679366,-122.872864),
    travelMode: "DRIVING"
}

test fiddle

Upvotes: 1

Related Questions