Google地图标记网址 [英] Google Map marker url

查看:102
本文介绍了Google地图标记网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮忙。我有下面的代码,但是当我点击标记时,它会将我重定向到同一页面:

 < script src =http ://maps.google.com/maps/api/js?sensor = falsetype =text / javascript>< / script> 

< script type =text / javascript>
函数initialize(){
var myOptions = {
zoom:14,
center:new google.maps.LatLng(<?php echo $ latitude;?> ;, <?php echo $ longitude;?>),
mapTypeId:google.maps.MapTypeId.ROADMAP,
streetViewControl:true,
scrollwheel:false
}

var map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);

for(var i = 0; i< locations.length; i ++){
var image = new google.maps.MarkerImage('images / greenmarkers /'+ i +'。 PNG');
var location = locations [i];
var myLatLng = new google.maps.LatLng(location [1],location [2]);
var marker = new google.maps.Marker({
position:myLatLng,
map:map,
icon:image,
title:location [0],
url:location [3]
});


google.maps.event.addListener(marker,'click',function(){
window.location.href = marker.url;
}) ;
}
}
< / script>

< script type =text / javascript>
var locations = [['test',63.3740200000000,19.6301320000000,'http://www.test.com'],['test1',63.3725155758185,19.6264879703522,'http://www.test1.com' ],['test2',63.3762550022764,19.6305649280548,'http://www.test2.com']];
< / script>


解决方案

这是一个工作代码:

  function loadURL(marker){
return function(){
window.location.href = marker.url;



函数initialize(){
var myOptions = {
zoom:5,
center:new google.maps。 LatLng(50.00,50.00),
mapTypeId:google.maps.MapTypeId.ROADMAP,
streetViewControl:true,
滚动:false
}

位置= [[aaa,51.00,51.00,http://www.atoztoa.com],[bbb,52.00,52.00,http://www.google.com]];

var map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);

for(var i = 0; i< locations.length; i ++){
var image = new google.maps.MarkerImage('roundedbutton1.png');
var location = locations [i];
var myLatLng = new google.maps.LatLng(location [1],location [2]);
var marker = new google.maps.Marker({
position:myLatLng,
map:map,
icon:image,
title:location [0],
url:location [3]
});

google.maps.event.addListener(标记,'click',loadURL(marker));
}
}


Can anybody help. I have below code but when I click on the marker it redirects me to the same page:

<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>

<script type="text/javascript"> 
function initialize() {
  var myOptions = {
    zoom: 14,
    center: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    streetViewControl: true,
    scrollwheel: false
  }

  var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

  for (var i = 0; i < locations.length; i++) {
      var image = new google.maps.MarkerImage('images/greenmarkers/'+ i +'.png');
      var location = locations[i];
      var myLatLng = new google.maps.LatLng(location[1], location[2]);
      var marker = new google.maps.Marker({
          position: myLatLng,
          map: map,
          icon: image,
          title: location[0],
          url: location[3]
      });


google.maps.event.addListener(marker, 'click', function() {
  window.location.href = marker.url;
});
  }
}
</script>

<script type="text/javascript"> 
var locations = [['test', 63.3740200000000, 19.6301320000000, 'http://www.test.com'],['test1', 63.3725155758185, 19.6264879703522, 'http://www.test1.com'],['test2', 63.3762550022764, 19.6305649280548, 'http://www.test2.com']];
</script> 

解决方案

Here is a working code:

function loadURL(marker) {
    return function () {
        window.location.href = marker.url;
    }
}

function initialize() {
  var myOptions = {
    zoom: 5,
    center: new google.maps.LatLng(50.00, 50.00),
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    streetViewControl: true,
    scrollwheel: false
  }

  locations=[["aaa",51.00, 51.00, "http://www.atoztoa.com"], ["bbb",52.00, 52.00, "http://www.google.com"]];

  var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

  for (var i = 0; i < locations.length; i++) {
      var image = new google.maps.MarkerImage('roundedbutton1.png');
      var location = locations[i];
      var myLatLng = new google.maps.LatLng(location[1], location[2]);
      var marker = new google.maps.Marker({
          position: myLatLng,
          map: map,
          icon: image,
          title: location[0],
          url: location[3]
      });

        google.maps.event.addListener(marker, 'click', loadURL(marker));
  }
}

这篇关于Google地图标记网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆