我有一个要求在谷歌地图。我有起点和终点。在他们中间,很少有路可走。我必须连接起点和终点通过路径点。这是可行的谷歌地图api,我已经这样做了。但有一种情况是,我要画一条铁路路线,即两个支线会透过铁路连接起来。所以,我有一条有汽车路线和铁路路线的路线。
样本:以A,B,C和D为例。
A-起点,B- WayPoint 1,C- Waypoint 2,D-端点
A至B车路线
B至C铁路路线
C至D车路线
我该怎么做呢?
请指引我!
发布于 2016-03-16 07:11:28
我希望这个用于您的示例,flightPlanCoordinates,,必须注册,YOUR_API_KEY,,还有更改,您的位置,纬度和经度,YOUR_API_KEY javascript变量值。
https://developers.google.com/maps/documentation/javascript/examples/polyline-simple?authuser=2
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polylines</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// This example creates a 2-pixel-wide red polyline showing the path of William
// Kingsford Smith's first trans-Pacific flight between Oakland, CA, and
// Brisbane, Australia.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: {lat: 0, lng: -180},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
var flightPlanCoordinates = [
{lat: 37.772, lng: -122.214},
{lat: 21.291, lng: -157.821},
{lat: -18.142, lng: 178.431},
{lat: -27.467, lng: 153.027}
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
</body>
</html>https://stackoverflow.com/questions/36028790
复制相似问题