问题
HeIIo, using google map API with search I'm able to find a certain place and then store it's details. However, the array doesn't contain google maps link which would open this place on google maps.
Via API I receive place_id which, as I feel, should be enough to build a full google maps link; however, I can't find a way to do that. Can anyone advise me on how to do that.
Thank you for your time.
回答1:
Try below syntax. I hope it helps
https://www.google.com/maps/place/?q=place_id:ChIJp4JiUCNP0xQR1JaSjpW_Hms
回答2:
Here is an official url to search for a placeId
with a fallback to an address
if the placeId
does not exist
https://www.google.com/maps/search/?api=1&query=<address>&query_place_id=<placeId>
no token required, works on Android, iOS (as well as iOS 11) and web
回答3:
There is no documentation for the expected parameters on https://www.google.com/maps/place , so this may only be a workaround(at least it currently works for me).
The following URL-format seems to give the desired result in most cases:
https://www.google.com/maps/place/[place-name]/@[latitude],[longitude],[zoom]z/
You may create this URL based on the place-name and the place-geometry
function initialize() {
var ac = new google.maps.places.Autocomplete(document.getElementById('pac'));
google.maps.event.addListener(ac, 'place_changed', function() {
var place = this.getPlace(),
link = document.getElementById('link');
if (!place.geometry) {
link.textContent = '';
} else {
var zoom = 17,
url = 'https://www.google.com/maps/place/' +
encodeURIComponent(place.name) + '/@' +
place.geometry.location.toUrlValue() + ',' +
zoom + 'z/';
link.href = link.textContent = url;
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3&libraries=places">
</script>
<input id="pac" />
<br/>
<a id="link" href="" target="_blank"></a>
回答4:
There is a way of always getting the right URL but it does require an additional request.
You can use the place_id to get the place details with
https://maps.googleapis.com/maps/api/place/details/json?key=YOURAPIKEY&placeid=THEPLACEID
The response from that has a ['result']['url'] field which always opens up the right place.
eg. https://maps.google.com/?cid=10254754059248426663
回答5:
You can use google embed API, and take src as a link: eg:
https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY
&q=place_id:YOUR_PLACE_ID
Docs: https://developers.google.com/maps/documentation/embed/guide#place_mode
来源:https://stackoverflow.com/questions/30857150/getting-google-maps-link-from-place-id