谷歌地图中两点之间的多条折线

Multiple polyline between two point in google map

本文关键字:之间 折线 两点 谷歌地图      更新时间:2024-06-28

我正在为我的项目开发谷歌地图。我需要在两个地方(点)之间画多条线。我不知道,有可能吗?。请任何人帮我。

google地图API中没有多行支持。。。但是你可以用javascript来实现。

折线示例:

https://developers.google.com/maps/documentation/javascript/examples/polyline-simple

API:

https://developers.google.com/maps/documentation/javascript/reference?hl=pt-BR#多段线

更多示例:

https://developers.google.com/maps/documentation/javascript/examples/

使用以下函数在两点之间画线,我将第一点和第二点的map和lat和long传递给该函数。

var mapOptions = {
    zoom: zoom,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas_'+id), mapOptions);    
function poliLines(map, latPointBefore, lonPointBefore, latPointAfter, lonPointAfter){
        var routes = [
          new google.maps.LatLng(latPointBefore, lonPointBefore)
          ,new google.maps.LatLng(latPointAfter, lonPointAfter)
        ];
        var polyline = new google.maps.Polyline({
           path: routes
           , map: map
           , strokeColor: '#ff0000'
           , strokeWeight: 5
           , strokeOpacity: 0.5
           , clickable: false
       });
}