当前位置: 代码迷 >> Web前端 >> 施用Google map 绘制折线
  详细解决方案

施用Google map 绘制折线

热度:192   发布时间:2012-07-25 09:43:05.0
使用Google map 绘制折线

Polyline 就是在地图上绘制的一系列直线段线,折线将一系列坐标指定为 LatLng 对象的数组。

可调用 PolylinegetPath() ,它会传回 MVCArray 类型的数组,包含点的坐标值。绘制折线的时候使用push方法将点的坐标添加进数组中。

function drawPolygonLine(){
	var polyOptions = {
          strokeColor: '#000000',
          strokeOpacity: 1.0,
          strokeWeight: 3
        };
    var poly = new google.maps.Polyline(polyOptions);
      poly.setMap(mapObj);
	google.maps.event.addListener(mapObj, 'click', function(event){
	      var path = poly.getPath(); 
              path.push(event.latLng); 
	       var marker = new google.maps.Marker({
		        position: event.latLng,
			title: '#' + path.getLength(),
			map: mapObj 
		}); 
	});
}  
  相关解决方案