gmap


<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>画线</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>

<script type="text/javascript">

var poly;
var map;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();


var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
var centerPoint = new google.maps.LatLng(23.0999442125314, 113.203125);
var myOptions = {
zoom: 4,
center: centerPoint,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

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

var polyOptions = {
strokeColor: 'red',
strokeOpacity: 1.0,
strokeWeight: 3
}
poly = new google.maps.Polyline(polyOptions);
poly.setMap(map);
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
var point = new google.maps.LatLng (37.37015718405753, 114.609375);
addLatLng(point,'A点','理','2011-11-21');

var point = new google.maps.LatLng (39.13006024213511, 115.48828125);
addLatLng(point,'B点','宁','2012-01-01');

var point = new google.maps.LatLng(23.241346102386135, 114.169921875);
addLatLng(point,'广州','xx','2012-01-16');
//calcRoute('37.37015718405753, 114.609375','39.13006024213511, 115.48828125');
//calcRoute('39.13006024213511, 115.48828125','23.241346102386135, 114.169921875');
}
</script>

<script type="text/javascript">

function addLatLng(point,mytitle,myname,time) {
var path = poly.getPath();
path.push(point);

var marker = new google.maps.Marker({
position: point,
title: mytitle,
map: map
});

//查询地址
// codeLatLng(point);
geocoder.geocode({'latLng': point}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {

var con='姓名: '+myname +'<br> 时间: '+time+' <br>所在地:'+ results[1].formatted_address;
attachSecretMessage(marker,con);
}
} else {

alert("Geocoder failed due to: " + status);

}
});

}


function attachSecretMessage(marker,mycontent) {
var infowindow = new google.maps.InfoWindow(
{ content: mycontent,
size: new google.maps.Size(50,50)
});

google.maps.event.addListener(marker, 'click', function(response) {



infowindow.open(map,marker);
map.setCenter(marker.position);
map.setZoom(6);
});
}

//起点 终点
function calcRoute(start,end) {

var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
}

</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值