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
Google maps 获取多段线上的点_Google Maps_Google Api_Google Api Js Client - Fatal编程技术网

Google maps 获取多段线上的点

Google maps 获取多段线上的点,google-maps,google-api,google-api-js-client,Google Maps,Google Api,Google Api Js Client,我使用Google Maps API在两点之间绘制了一条多段线。现在我想沿着同一条线生成额外的点。是否有一个函数可以执行此操作 我不想在直线上添加一些随机点;我希望点位于两个端点之间生成的曲线上。您可以使用计算点在直线任何线段上的位置: var marker2 = new google.maps.Marker({ map: map, position: google.maps.geometry.spherical.interpolate( new google.maps.LatL

我使用Google Maps API在两点之间绘制了一条多段线。现在我想沿着同一条线生成额外的点。是否有一个函数可以执行此操作

我不想在直线上添加一些随机点;我希望点位于两个端点之间生成的曲线上。

您可以使用计算点在直线任何线段上的位置:

var marker2 = new google.maps.Marker({
  map: map,
  position: google.maps.geometry.spherical.interpolate(
    new google.maps.LatLng(flightPlanCoordinates[1].lat,flightPlanCoordinates[1].lng),
    new google.maps.LatLng(flightPlanCoordinates[2].lat,flightPlanCoordinates[2].lng),
    0.6)
});
(请注意,插值函数仅接受对象作为参数,而不是,至少此时是这样)

代码片段:

//此示例创建一条2像素宽的红色多段线,显示William的路径
//Kingsford Smith在加利福尼亚州奥克兰和加利福尼亚州之间的首次跨太平洋航班
//澳大利亚布里斯班。
函数initMap(){
var map=new google.maps.map(document.getElementById('map'){
缩放:3,
中心:{
纬度:0,
液化天然气:-180
},
mapTypeId:'地形'
});
var FlightPlan坐标=[{
拉脱维亚:37.772,
液化天然气:-122.214
}, {
纬度:21.291,
液化天然气:-157.821
}, {
lat:-18.142,
液化天然气:178.431
}, {
lat:-27.467,
液化天然气:153.027
}];
var flightPath=new google.maps.Polyline({
路径:FlightPlan坐标,
测地线:正确,
strokeColor:“#FF0000”,
笔划不透明度:1.0,
冲程重量:2
});
var marker=new google.maps.marker({
地图:地图,
位置:google.maps.geometry.spherical.interpolate(新建google.maps.LatLng(flightPlanCoordinates[0].lat,flightPlanCoordinates[0].lng),新建google.maps.LatLng(flightPlanCoordinates[1].lat,flightPlanCoordinates[1].lng),0.75)
});
var marker2=新的google.maps.Marker({
地图:地图,
位置:google.maps.geometry.sphereal.interpolate(新建google.maps.LatLng(flightPlanCoordinates[1].lat,flightPlanCoordinates[1].lng),新建google.maps.LatLng(flightPlanCoordinates[2].lat,flightPlanCoordinates[2].lng),0.6)
});
var marker3=新的google.maps.Marker({
地图:地图,
位置:google.maps.geometry.sphereal.interpolate(新建google.maps.LatLng(flightPlanCoordinates[2].lat,flightPlanCoordinates[2].lng),新建google.maps.LatLng(flightPlanCoordinates[3].lat,flightPlanCoordinates[3].lng),0.8)
});
flightPath.setMap(map);
}
/*始终明确设置贴图高度以定义div的大小
*包含映射的元素*/
#地图{
身高:100%;
}
/*可选:使示例页面填充窗口*/
html,
身体{
身高:100%;
保证金:0;
填充:0;
}