我在谷歌地图折线问题。谷歌地图折线:标记包含点击LatLng的两个折线坐标
我从一点到另一点有一条折线。当我点击折线时,我需要两端的纬度和纬度。
请任何人都可以帮我吗?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize()
{
var myLatLng = new google.maps.LatLng(0, -180);
var myOptions = {zoom: 2,center: myLatLng,mapTypeId: google.maps.MapTypeId.TERRAIN};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var flightPlanCoordinates = [ new google.maps.LatLng(17.772323, 78.214897),
new google.maps.LatLng(28.46758, 78.027892),
new google.maps.LatLng(29.46758, 88.027892),
new google.maps.LatLng(20.46758, 97.027892),
new google.maps.LatLng(17.772323, 78.214897)
];
var flightPath = new google.maps.Polyline({path: flightPlanCoordinates,strokeColor: "#FF0000",strokeOpacity: 1.,strokeWeight: 10});
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(flightPath, 'click', function()
{
//attached click event now do your logic here
this.getPath().forEach(function(el, index)
{
//infowindow.setContent('Point ' + index + ' : Latitude = ' + el.lat() + ' | Longitude = ' + el.lng());
alert('Point ' + index + ' : Latitude = ' + el.lat() + ' | Longitude = ' + el.lng());
});
});
flightPath.setMap(map);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width=100%; height:60%"></div>
</body>
</html>
普拉迪普,你问了许多新的问题kjy112。他正在回答他们所有的问题,而你只是不给他答应给予的赞赏。如果您有更多问题,请提出一个新的单独问题。 – 2011-04-06 13:34:44
@Wouter:实际上我不知道如何投票,因为我新到了stackoverflow .....现在我知道了,我已经投了答案..... – 2011-04-07 04:17:12