2

I want to pass in an array of google place id values and output the formatted addresses of each one onto a google map marker (multiple markers). My question is similar to this one: Multiple markers Google Map API v3 from array of addresses and avoid OVER_QUERY_LIMIT while geocoding on pageLoad

but the big difference is that I only have the place id and not any address. I wish to convert it into an address so that I can use the method showed in the link above from the other stackoverflow method.

So far, I tried using a getJSon method to retrieve the place id url:

$.getJSON('https://maps.googleapis.com/maps/api/place/details/json?placeid=somethingsomething&key=mykey, null, function (data) { var p = data.results[0].geometry.location;

  var latlng = new google.maps.LatLng(p.lat, p.lng);
  new google.maps.Marker({
      position: latlng,
      map: map,


  });

});

This does not appear to be working as I cannot retrieve the json object due to CORS problems. If I format as a ajax call with JSONP format, it throws a unexpected token error (because the string itself is JSON). Im just looking for a simple way to take place id values, put it into a function, and spit out the formatted address. Thanks!

TIna
  • 21
  • 1

1 Answers1

1

In order to avoid CORS problems you have to use places library of Maps JavaScript API. The places library has place details functionality that allows to get detailed information about place ID. You can also use reverse geocoding service of Maps JavaScript API that allows to get address by its place ID.

The important thing you should be aware of is that you can pass only one place ID in each request and that user session in Maps JavaScript API has limits. Initially you have a bucket of 10 requests, once you used all requests of the bucket you can execute 1 request per second.

If you need batch reverse geocoding, Google recommends to do it in server side code. In this case you can use Geocoding API web service and usage limits will be 50 requests per second.

You can easily change code from the mentioned question changing the address parameter in requests to corresponding place ID parameter. Just read documentation that I mentioned before.

I hope this helps!

xomena
  • 31,125
  • 6
  • 88
  • 117