4
A
回答
10
这实际上很容易做到。只需将事件处理程序附加到您的标记,然后通过将window.location.href
设置为您的URL来启动该链接。看看下面的例子,我想这应该是不言而喻的:
使用v3 API:在
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps Marker as a Link</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false"
type="text/javascript"></script>
</head>
<body onunload="GUnload()">
<div id="map" style="width: 500px; height: 400px;"></div>
<script type="text/javascript">
var map = new GMap2(document.getElementById("map"));
var centerPoint = new GLatLng(35.55, -25.75);
map.setCenter(centerPoint, 2);
var marker = new GMarker(map.getCenter());
marker.url = 'http://www.google.com/';
map.addOverlay(marker);
GEvent.addListener(marker, 'click', function() {
window.location.href = marker.url;
});
</script>
</body>
</html>
以上的例子将添加标记的地方:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google Maps Marker as a Link</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"
type="text/javascript"></script>
</head>
<body>
<div id="map" style="width: 500px; height: 400px;"></div>
<script type="text/javascript">
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: new google.maps.LatLng(35.55, -25.75),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: map.getCenter(),
url: 'http://www.google.com/',
map: map
});
google.maps.event.addListener(marker, 'click', function() {
window.location.href = marker.url;
});
</script>
</body>
</html>
使用V2 API大西洋。当你点击它时,你会被转发到一个流行的搜索引擎。
2
为了得到这个在新标签中打开添加正确后, “window.location.href = marker.url;” 以下内容:
window.open(this.url, '_blank');
所以你会:
google.maps.event.addListener(marker, 'click', function() {
window.location.href = marker.url;
window.open(this.url, '_blank');
});
相关问题
- 1. 谷歌地图标记作为链接
- 2. 打开谷歌地图标记从地图之外的链接
- 3. 谷歌地图链接
- 4. 谷歌地图标记infowindow
- 5. android谷歌地图标记
- 6. 谷歌地图标记DROP
- 7. 谷歌地图标记
- 8. 标记谷歌地图
- 9. 谷歌地图 - 多标记
- 10. 谷歌地图标记
- 11. 标记在谷歌地图
- 12. 谷歌地图API标记
- 13. 谷歌地图 - 多标记
- 14. 谷歌地图:getSelected标记
- 15. RxJS谷歌地图标记
- 16. 角谷歌地图标记
- 17. 谷歌地图标记
- 18. 谷歌地图 - 添加新的图标作为标记
- 19. 色调为rgb谷歌地图标记
- 20. 谷歌地图标记为Reactjs组件
- 21. 谷歌地图clearMarkers标记为空时
- 22. 谷歌地图标记为纽带
- 23. 如何添加独特的链接到谷歌地图标记
- 24. Javascript谷歌地图Api,多个标记链接,只geoceder
- 25. 控制infowindow的谷歌地图链接就像标记一样
- 26. 使用谷歌地图的标记群集链接
- 27. 在谷歌地图中添加标记谷歌地图反应
- 28. 谷歌地图标记为SVG(图像PNG标记内)
- 29. 链接到谷歌地图地址API
- 30. 标记与标签谷歌地图
谢谢老兄! – 2010-06-17 07:41:56
嘿+1已添加,但如果你想在新窗口中打开此链接,我试过window.open = marker.url;然后像 这样的属性url:“http://www.google.com”, target:“_blank”到标记对象但无济于事, – defau1t 2011-12-18 20:24:00