Steps:
When using the same key for place autocomplete or for maps, everything still works fine. I would expect it to work fine with Place Photos as well, but it doesn't.
What might cause this issue?
The place autocomplete is a part of Google Maps JavaScript API, so an API key with HTTP referrer restriction works well.
The Google place photo is a part of Places API web service. The web services support only IP address restrictions, they will fail with HTTP referrer restrictions on API keys.
You can read which restriction is applicable for each API here:
https://developers.google.com/maps/faq#keysystem
If your intention is using place photos in JavaScript code, you can just obtain a place from autocomplete using getPlace method as shown in this example and loop through photos array of PlaceResult object.
The google.maps.places.PlacePhoto object provides the method getUrl() that returns URL of the place photo. Use this method to get the URL of image.
Have a look at documentation for further details:
https://developers.google.com/maps/documentation/javascript/reference#PlacePhoto
place.photos.forEach(function (placePhoto) {
var url = placePhoto.getUrl({
maxWidth: 600,
maxHeight: 400
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With