Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将谷歌地图中的所有标记与路径连接起来?_Javascript_Google Maps_Path_Directory_Latitude Longitude - Fatal编程技术网

Javascript 如何将谷歌地图中的所有标记与路径连接起来?

Javascript 如何将谷歌地图中的所有标记与路径连接起来?,javascript,google-maps,path,directory,latitude-longitude,Javascript,Google Maps,Path,Directory,Latitude Longitude,我是谷歌地图(API)的新手,我需要得到以下结果: 目前,我知道如何渲染地图并在地图上放置标记(基于经度和纬度) 可能有很多标记。我正在寻找一种将标记与预览图像中的路径连接起来的方法 我不知道我应该搜索什么,我需要你们的帮助,伙计们。谢谢你的建议 下面是一个例子: 另外,请参见 如果您不知道如何将响应对象映射到LatLng对象数组,下面是一个示例: var flightPath = responseArray.map(function (item) { return new googl

我是谷歌地图(API)的新手,我需要得到以下结果:

目前,我知道如何渲染地图并在地图上放置标记(基于经度和纬度)

可能有很多标记。我正在寻找一种将标记与预览图像中的路径连接起来的方法

我不知道我应该搜索什么,我需要你们的帮助,伙计们。谢谢你的建议

下面是一个例子:

另外,请参见

如果您不知道如何将响应对象映射到
LatLng
对象数组,下面是一个示例:

var flightPath = responseArray.map(function (item) {
    return new google.maps.LatLng(item.latitude, item.longitude);
});

我也很难找到这方面的细节——在你的responseArray附录中仍然不清楚。你能扩展吗?最后你应该添加这个,flightPath.setMap(map);
[
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
]
  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)
  ];
  var flightPath = new google.maps.Polyline({
    path: flightPlanCoordinates,
    strokeColor: "#FF0000",
    strokeOpacity: 1.0,
    strokeWeight: 2
  });
var flightPath = responseArray.map(function (item) {
    return new google.maps.LatLng(item.latitude, item.longitude);
});