如何:Google标记网址在新标签页中打开

时间:2017-07-09 09:13:49

标签: javascript google-maps dictionary url marker

我想让我的地图标记在新标签页中打开地图。你还有什么建议吗?

var map = $that.data('googleMap');

                            google.maps.event.addListener(marker, 'click', 
function() {
                                infowindow.open(map, marker);
                            });
                        } else if(params.url) {
                            google.maps.event.addListener(marker, 'click', 
function() {
                                document.location = params.url;
                            });
                        }

在footer.tpl中我有这个:

$("#mapContact").addMarker({
      coords: [49.004674, 14.770050],
      icon: '/themes/organie4/img/dorado/contact/location-pin.png',
      url: 'https://www.google.com/maps/place/Husova+75,+Třeboň+I,+379+01+Třeboň/'
    });

谢谢!

2 个答案:

答案 0 :(得分:0)

有这样的事情:

var map = ... // Map declaration

var marker = new google.maps.Marker({
    position: {lat: 49.004674, lng: 14.770050},
    map: map,
    icon: '/themes/organie4/img/dorado/contact/location-pin.png',
    url: 'https://www.google.com/maps/place/Husova+75,+Třeboň+I,+379+01+Třeboň/'
});

var infowindow = new google.maps.InfoWindow({
    content: "Some text"
});

marker.addListener('click', function() {
    if (this.url) {
        document.location = this.url;
        // Or like this if you want a new tab : window.open(this.url, '_blank');
    } else {
        infowindow.open(map, this);
    }       
});

我希望这会对你有所帮助。

修改: 的 1)

    google.maps.event.addListener(marker, 'click', function() {
       infowindow.open(map, marker);
    });
} else if(params.url) {
    google.maps.event.addListener(marker, 'click', function() {
        document.location = params.url;
    });
}

替换为:

marker.addListener('click', function() {
    if (this.url) {
        document.location = this.url;
        // Or like this if you want a new tab : window.open(this.url, '_blank');
    } else {
        infowindow.open(map, this);
    }       
});

<强> 2)

$("#mapContact").addMarker({
    coords: [49.004674, 14.770050],
    icon: '/themes/organie4/img/dorado/contact/location-pin.png',
    url: 'https://www.google.com/maps/place/Husova+75,+Třeboň+I,+379+01+Třeboň/'
});

等同于(但使用&#34;标记&#34;变量):

var marker = new google.maps.Marker({
    position: {lat: 49.004674, lng: 14.770050},
    map: map,
    icon: '/themes/organie4/img/dorado/contact/location-pin.png',
    url: 'https://www.google.com/maps/place/Husova+75,+Třeboň+I,+379+01+Třeboň/'
});

第3)

我不知道那是什么:

var map = $that.data('googleMap');

这是地图声明的一个例子:

var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 49.004674, lng: 14.770050},
    zoom: 7
});

<强> 4)

我不知道你的&#34; infowindow&#34;声明,但这是一个简单的例子:

var infowindow = new google.maps.InfoWindow({
    content: "Some text"
});

答案 1 :(得分:0)

不确定。这里是。

<强> jquery.googlemap.js

var map = $that.data('googleMap');

    marker.addListener('click', function() {
    if (this.url) {
           window.open(this.url, '_blank')
          // Or like this if you want a new tab : window.open(this.url, '_blank');
                   } else {
                                infowindow.open(map, this);
                            }       
                        });

<强> footer.tpl

var marker = new google.maps.Marker({
        position: {lat: 49.004674, lng: 14.770050},
        map: map,
        icon: '/themes/organie4/img/dorado/contact/location-pin.png',
        url: 'https://www.google.com/maps/place/Husova+75,+Třeboň+I,+379+01+Třeboň/'
  });

当我更改 footer.tpl 我的页面“联系人”时抛出 500(内部服务器错误)