0

I am looking for a way to avoid being charged for

  • Places API Atmosphere Data
  • Places API Contact Data

I only need to reverse the place id to its formatted_address. Any idea about what changes I need to do in the code bellow?

Related question, although I am not using Autocomplete but PlacesService.


$('.company_location_id').each(function(i, obj) {
    if ($(this).length > 0) {
        if ($(this).val()) {
            var request = {
                placeId: $(this).val()
            };

            service = new google.maps.places.PlacesService(document.getElementsByClassName($(this).attr('class'))[0]);
            service.getDetails(request, callback);

            var new_text = $(this)

            function callback(place, status) {
                if (status == google.maps.places.PlacesServiceStatus.OK) {
                    $(new_text).next().text(place.formatted_address);
                }
            }
        }
    }
});
anvd
  • 3,997
  • 19
  • 65
  • 126

1 Answers1

1

In order to avoid charges for Atmosphere Data and Contact Data using the PlacesService, you should specify a list of fields to be retrieved in the PlaceDetailsRequest object that you pass as a first parameter in getDetails() function.

Have a look at the documentation of PlaceDetailsRequest interface: https://developers.google.com/maps/documentation/javascript/reference/places-service#PlaceDetailsRequest

As you can see this interface has fields property

fields - Fields to be included in the details response. For a list of fields see PlaceResult. Nested fields can be specified with dot-paths (for example, "geometry.location").

So, you should define request in your code as

var request = {
    placeId: $(this).val(),
    fields: ["formatted_address"]
};

I hope this helps!

xomena
  • 31,125
  • 6
  • 88
  • 117