【问题标题】:Link marker to url Google Maps [duplicate]链接标记到 url Google Maps [重复]
【发布时间】:2014-02-22 19:12:32
【问题描述】:

简单的问题:

我正在尝试将我的标记链接到 Google 地图 (API v3) 上的外部网址。 现在可以使用http://www.google.com作为链接。

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>

【问题讨论】:

  • link my marker to an external url 是什么意思?
  • 你的意思是链接?在单击标记时打开另一个链接?

标签: javascript api google-maps google-maps-api-3


【解决方案1】:

您需要在标记处添加一个谷歌地图点击event

google.maps.event.addListener(marker, 'click', function () {
  window.location.href = 'http://www.google.com';
});

在定义 marker 后立即执行此操作。

【讨论】:

  • 简单又好用!谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多