Google Maps API v3: Opening the link on a marker in a new window

seems like a pretty basic thing, but I don't seem to be finding the answer. Here's my Google Maps code:

var marker = new google.maps.Marker({
      position: new google.maps.LatLng(123, 123),
      url: "",
      map: map


google.maps.event.addListener(marker, 'click', function() {
    window.location.href = marker.url;

What do I need to change, to open the link in a new window?

Many thanks!



You have to use the method open of the window object like this:"");

So your code will be something like this:

google.maps.event.addListener(marker, 'click', function() {;

Visit this link for an overview of the open method and the options you can set.


So I used this approach but when I was in a loop making lots of markers, each with a different URL, this was the approach I needed to take.

    var newLatlng = new google.maps.LatLng(row[0], row[1]);
    var marker = new google.maps.Marker({
        position: newLatlng,
        map: map,
        title: row[2],
        url: row[3]
    google.maps.event.addListener(marker, 'click', function() {''+this.url);

Note that the key was using this.url in the listener code. If I used marker.url in the listener code, it would open the last of many urls for all of the markers.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.