2015-05-12 95 views
0

我正尝试使用Google Maps API v3在我的网站上显示地图。我希望它能显示我的城市的一些公交线路。它应该看起来像一条彩色路径(例如1号线的红色路径),它显示了公交车的行程。向Google地图添加路径(API v3)

这是我到现在为止:http://dejoridavid.pe.hu/sasabus/map.php。在地图上标记显示公交车的位置,只有线路径丢失。如何使用Google Maps API v3为我的地图添加路径?它应该是从A到B到C等的路径,然后再到达A.

+1

听起来像是你要使用的[路线服务(https://developers.google.com/maps/documentation/的JavaScript /方向)。或者,您可能需要绘制大量[多段线](https://developers.google.com/maps/documentation/javascript/shapes#polylines) – duncan

回答

0

Google Maps API docs采取的行动(我加了注释,以澄清所发生的事情)

// initialize a mapOptions object 
var mapOptions = { 
    zoom: 3, 
    center: new google.maps.LatLng(0, -180), 
    mapTypeId: google.maps.MapTypeId.TERRAIN 
}; 

// initialize a map object 
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); 

// initialize an array of LatLng objects. These are your markers in your city 
var flightPlanCoordinates = [ 
     new google.maps.LatLng(37.772323, -122.214897), 
     new google.maps.LatLng(21.291982, -157.821856), 
     new google.maps.LatLng(-18.142599, 178.431), 
     new google.maps.LatLng(-27.46758, 153.027892)]; 

// initialize a Polyline object. You can set the color, width, opacity, etc. 
var flightPath = new google.maps.Polyline({ 
    path: flightPlanCoordinates, 
    geodesic: true, 
    strokeColor: '#FF0000', 
    strokeOpacity: 1.0, 
    strokeWeight: 2 
}); 

// set the polyline's map with your map object from above. 
flightPath.setMap(map); 
相关问题