Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138134

JS Maps API: Malformed url on getDetails

$
0
0

Irm working with the Javascript API for Google Maps to retrieve a nearby places request then get somes details from the places returned.

The nearby places request works well, but when I'm trying to get the details, the url fields parameter seems malformed, so google is returning all the fields and I'm billed for it...

I pointed it out by searching into the network console, the url requested is:

https://maps.googleapis.com/maps/api/place/js/PlaceService.GetPlaceDetails?2sfr-FR&10e3&14m1&1sChIJaR_1flly5kcRKckAY1gMTzo&16m1&1splace_id%2Cname%2Caddress_components&17m1&2e1&callback=xdc._nj45gn&key=myApiKey&token=118841

Malformed url from google maps javascrip api

And since the november update, for sure, it sends to me a thousand of deprecated open_hours.open_now error (because of the fact that all fields is returned, even those deprecated), but I guess this will be solved when my principal issue will be solved.

I'm using getDetails in two places in my code with two different fields parameters, so I stored these in two distinct arrays which I insert when needed, but that's not the problem, I tried by simplifying the code with a basic search request but I didn't see any changes:

{
    placeId: place_id,
    fields: ['place_id', 'name', 'address_components']
}
// Or even more basic:
{
    placeId: place_id,
    fields: ['place_id,name,address_components']
}

Here is my actual code:

const basic_search_fields = [
    'place_id',
    'name',
    'address_components'
]

const detailled_search_fields = [
    'place_id',
    'name',
    'address_components',
    'geometry',
    'formatted_address',
    'photo',
    'url',
    'formatted_phone_number',
    'international_phone_number',
    'opening_hours',
    'website'
]
/**
    * Construct a place search request
    */
createPlaceRequestFor: function (place, detailled = false) {
    // Init the request with the fixed datas
    let request = {
        placeId: place.place_id,
    }

    // Set the fields for a basic or a detailled search
    request.fields = detailled ? detailled_search_fields : basic_search_fields
    return request
},
executePlaceRequest: function (request) {
    return new Promise((resolve, reject) => {
        this.PlacesService.getDetails(request, (results, status) => {
            if (status == this.Google.places.PlacesServiceStatus.OK) {
                resolve(results)
            }
            reject(status)
        })
    })
}

Viewing all articles
Browse latest Browse all 138134

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>