Ploum
Ploum

Reputation: 3

Google Maps API - Link to place detail page

I have a custom Google Maps where marker are populate dynamically and I try to redirect the marker link to the corresponding place details' page on Google Maps. For example, on marker click, I would like to open a new window to this link : https://www.google.com/maps/place/PMBCOM/@46.381949,6.236581,17z/data=!3m1!4b1!4m2!3m1!1s0x478c372f7df47135:0xff206d31a973eded

For now, I am able to redirect to the address, but it does not show the full Google My Business panel like on my previous link. Any ideas ?

Here is my code :

function initMap() {
    var myLatlng = new google.maps.LatLng(agence[0], agence[1]);
    var map = new google.maps.Map(document.getElementById('maps'), {
    center: myLatlng,
    zoom:17
});

var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);

service.getDetails({
    placeId: 'ChIJ71BChS4ujEcRclm9twk3Y04'
}, function(place, status) {
    if (status === google.maps.places.PlacesServiceStatus.OK) {
        var marker = new google.maps.Marker({
        map: map,
        position: place.geometry.location,
        title: place.name,
        url: 'https://www.google.com/maps/place/'+place.formatted_address
});
google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(place.name);
    infowindow.open(map, this);
    window.open(marker.url);
  });
}
});
}
google.maps.event.addDomListener(window, 'load', initMap);

Thanks for your help

Upvotes: 0

Views: 692

Answers (1)

Ma Yubo
Ma Yubo

Reputation: 219

look this part

url: 'https://www.google.com/maps/place/'+place.formatted_address

google cannot locate this company in this way

change to

url: place.url

I think this is what you want

Upvotes: 1

Related Questions