how can i plot a route map?

时间:2015-06-15 14:42:23

标签: javascript google-maps plot

I am writing a simple application to plot multiple marker in the google map and connect it thought a path as it looks like a route . I can plot multiple marker . and search some article which plot the route map . but i can not plot it . i wrote in javascript

<html> 
<head>
<title>Google Maps Multiple Markers</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"   type="text/javascript"></script>
</head>
<body>
<div id="map" style="height: 1000px; width: 800px;">
</div>
<script type="text/javascript">
var markers= [
 {
 "lat": '13.03563',
 "lng": '77.51283',
  "description": '1'
  },
  {
  "lat": '13.04501',      
   "lng": '77.55674',
   "description": '2'
 },
 {
  "lat": '13.03747',
  "lng": '77.5629',
  "description": '3'
 ];
  var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 10,
 center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
  mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < markers.length; i++) { 
marker = new google.maps.Marker({
position: new google.maps.LatLng(markers[i].lat , markers[i].lng),
  map: map
});
}
</script>
</body>
</html>
     }
   ];

how can i draw the route ? any suggestion

2 个答案:

答案 0 :(得分:1)

您的代码适合我,只修了一些}]

http://jsfiddle.net/3qo8kg2o/

但我认为你应该使用polyline代替。

答案 1 :(得分:0)

Seem you are searching for google maps direction service

look ad this Direction documentation

and at this direction samples

If is not the direction servici what you are looking for but you want to connect the marker with a line. draw a LineString between every markers coordinate.