如何将所有标记与 Google 地图中的路径连接起来?
我是 Google 地图(API)新手,我需要获得以下结果:
目前,我知道如何渲染地图并在其上放置标记(基于经度和纬度)。
var map;
map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 7,
center: new google.maps.LatLng(response[0].latitude, response[0].longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
for (var i = 0; i < response.length; ++i) {
new google.maps.Marker({
'map' : map,
'position' : new google.maps.LatLng(response[i].latitude, response[i].longitude),
'title' : response[i].address
});
}
变量response
结构如下:
[
Object
address: "Krišjāņa Barona iela 25, Riga, LV-1011, Latvia"
latitude: "24.1245290"
longitude: "56.9528510"
__proto__: Object
,
Object
address: "Rīgas iela 1, Tukums, Tukuma novads, LV-3101, Latvia"
latitude: "23.1630590"
longitude: "56.9663880"
__proto__: Object
]
可能有很多标记。我正在寻找一种将标记与预览图像中的路径连接起来的方法。
我不知道我应该搜索什么,我需要你们的帮助,伙计们。谢谢指教!
I'm new to Google Maps (API) and I need to get the following result:
At the moment, I know how to render the map and place markers on it (based on longitude and latitude).
var map;
map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 7,
center: new google.maps.LatLng(response[0].latitude, response[0].longitude),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
for (var i = 0; i < response.length; ++i) {
new google.maps.Marker({
'map' : map,
'position' : new google.maps.LatLng(response[i].latitude, response[i].longitude),
'title' : response[i].address
});
}
Variable response
structure is like:
[
Object
address: "Krišjāņa Barona iela 25, Riga, LV-1011, Latvia"
latitude: "24.1245290"
longitude: "56.9528510"
__proto__: Object
,
Object
address: "Rīgas iela 1, Tukums, Tukuma novads, LV-3101, Latvia"
latitude: "23.1630590"
longitude: "56.9663880"
__proto__: Object
]
There could be a lot of markers. I'm looking for a way to join markers with paths like in the preview image.
I don't know for what I should search and I need your help in this, guys. Thanks in an advice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google 教程中的示例:
另请参阅
折线
的参考条目。如果您不知道如何将响应对象映射到
LatLng
对象数组,请参阅以下示例:An example from Google's tutorial:
Also, see the reference entry for
Polylines
.If you don't know how to map the response object to an array of
LatLng
objects, here's an example: