Google地图折线和标记在一起 [英] Google Maps Polyline and Marker together

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

问题描述

我有这个代码是为了完美的折线。如何为每个位置点添加标记?

I have this code for polyline which is working perfect. How do i add marker for each of location point?

var userCoor = [
<?php
for($i=0; $i<sizeOf($lat); $i++)
echo "new google.maps.LatLng({$lat[$i]}, {$long[$i]}),";
?>
];

var userCoordinate = new google.maps.Polyline({
path: userCoor,
strokeColor: "#FF0000",
strokeOpacity: 1,
strokeWeight: 2
});

userCoordinate.setMap(map);

我试过

I tried

var infowindow = new google.maps.InfoWindow();

var marker, i;

for (i = 0; i < userCoor.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(userCoor[i][1], userCoor[i][2]),
    map: map
  });

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(userCoor[i][0]);
      infowindow.open(map, marker);
    }
  })(marker, i));
}
}

标记似乎缺失?任何想法如何?谢谢。

Marker seems missing? Any idea how? Thanks.

推荐答案

我在这里测试了一些假数据,但似乎没有问题。不同之处在于我为折线和 userCoor 使用 userCoorPath 来设置标记。我正在重复这些信息,但他们的使用方式有所不同。一个是LatLngs数组,另一个是字符串数组和两个浮点数。

I tested with some bogus data here and there doesn't seem to be a problem. The difference is I'm using userCoorPath for the polyline and userCoor to set the markers. I'm repeating the information, but they are being used differently. One is an array of LatLngs, the other an array of string and two floats.

http://jsfiddle.net/nSf9N/

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

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