gpt4 book ai didi

javascript - 如何在 google map api 中放置多个标记并绘制路线

转载 作者:行者123 更新时间:2023-11-30 10:01:50 24 4
gpt4 key购买 nike

我在一个变量中有经纬度 json

var path = [{"lat":"12.9247903824","lng":"77.5806503296"},{"lat":"10.9974470139","lng":"76.9459457397"}]

我已经根据经纬度值创建了路径

var marker = new google.maps.Marker({
position: pos,
map: map
});
var flightPath = new google.maps.Polyline({
path: path,
geodesic: true,
strokeColor: '#ff0000',
strokeOpacity: 1.0,
strokeWeight: 2,
map: map,
bounds: map.getBounds()
});

它是从点创建的路径。但只有一个标记显示。因为该标记必须显示在所有点(路径)中。

还有一个,我想获取所有lat,lng值的地址

最佳答案

您必须将您的点转换到 google.maps.latLng 点:

var pointsPath = [new google.maps.LatLng(12.9247903824,77.5806503296),new google.maps.LatLng(10.9974470139,76.9459457397)];

然后像这样初始化 map :

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


var flightPath = new google.maps.Polyline({
path: pointsPath,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});

flightPath.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);

希望对你有帮助

关于javascript - 如何在 google map api 中放置多个标记并绘制路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31199663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com