cameroncf
cameroncf

Reputation: 1

Link back to Google from API Marker

I'm using the Google Maps API v3 to generate some minimaps. I have one custom marker in a small map with controls hidden. This works great. Now, I'd like to add a link so that clicking this marker will open the full Google Maps with this location selected. Seems obvious.

I'm creating a marker like this.

var pin = new google.maps.LatLng(myLat,myLong);
var marker = new google.maps.Marker({
   position: pin,
   map: map,
   title:"Hello World"
});

This seems like it should be obvious, what am I missing? Do I need to construct my link and assign it myself?

Upvotes: 0

Views: 50

Answers (2)

cameroncf
cameroncf

Reputation: 1

Ended up finding the answer thusly:

google.maps.event.addListener(marker, 'click', function() {
    window.open("https://maps.google.com/maps?ll="+pin.toUrlValue(),'_blank');
});

Upvotes: 0

geocodezip
geocodezip

Reputation: 161404

This should work (not tested):

var pin = new google.maps.LatLng(myLat,myLong);
var marker = new google.maps.Marker({
   position: pin,
   map: map,
   title:"Hello World"
});
google.maps.addListener(marker, "click", function() {
   window.location = "https://maps.google.com/maps?ll="+pin.toUrlValue;
});

Working example (built on an existing example, not from the above code)

Upvotes: 1

Related Questions