javascript 链接标记到 url 谷歌地图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21457244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 20:57:48 来源:igfitidea点击:
Link marker to url Google Maps
提问by Dale
Simple question:
简单的问题:
Im trying to link my marker to an external url on a Google Map (API v3). Can just use http://www.google.comas the link for now.
我试图将我的标记链接到 Google 地图(API v3)上的外部网址。现在可以只使用http://www.google.com作为链接。
Javascript:
Javascript:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(-30.021664, 30.901578);
var mapOptions = {
zoom: 15,
center: myLatlng,
scrollwheel: false,
disableDefaultUI: true
}
var map = new google.maps.Map(document.getElementById('ContactMap'), mapOptions);
var image = '/Assets/Images/Icons/MapMarker.png';
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
animation: google.maps.Animation.DROP,
icon: image,
title: 'Perspex'
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
回答by Andy
You need to add a google maps click event
to the marker:
您需要添加一个谷歌地图点击event
标记:
google.maps.event.addListener(marker, 'click', function () {
window.location.href = 'http://www.google.com';
});
Do this immediately after defining marker
.
定义后立即执行此操作marker
。