Javascript 谷歌地图无限线/增加长度或lat lng计算
嘿,我想找到一种方法,在不改变方向的情况下增加线的长度 我用多段线试过了Javascript 谷歌地图无限线/增加长度或lat lng计算,javascript,jquery,google-maps,google-maps-api-3,coordinates,Javascript,Jquery,Google Maps,Google Maps Api 3,Coordinates,嘿,我想找到一种方法,在不改变方向的情况下增加线的长度 我用多段线试过了 var map; function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: {lat: 37.4419, lng: -122.1419}, zoom: 8 }); var line = new google.maps.Polyline({ path: [new go
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 37.4419, lng: -122.1419},
zoom: 8
});
var line = new google.maps.Polyline({
path: [new google.maps.LatLng(37.4419, -122.1419), new google.maps.LatLng(37.4519, -122.1519)],
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 10,
geodesic: true,
map: map
});
}
它的工作原理与预期相符
但我更希望像这样
或
我只有第一个例子中的两个坐标
它应该是测地的,理论上理想地绕着地球在同一个起点,所以它就像是无尽的
我还试图找到一种方法来计算更远的坐标,但搜索是一团混乱,因为everboidy想要找到计算距离的方法。
因此,有两个坐标在“直线通过方向”之后,但距离很长,比如大约1000公里。请让我知道您可以使用来计算直线的航向,并沿该航向将其延伸任意长的距离
代码片段::
var映射;
函数initMap(){
map=new google.maps.map(document.getElementById('map'){
中心:{
拉脱维亚:37.4419,
液化天然气:-122.1419
},
缩放:8
});
var line=新的google.maps.Polyline({
路径:[新建google.maps.LatLng(37.4419,-122.1419),新建google.maps.LatLng(37.4519,-122.1519)],
strokeColor:#FF0000“,
笔划不透明度:1.0,
冲程重量:10,
测地线:正确,
地图:地图
});
//从每一端沿其现有方向延伸线
//选择20e6米作为任意长度
var lineHeading=google.maps.geometry.spheremic.computeHeading(line.getPath().getAt(0),line.getPath().getAt(1));
var newPt0=google.maps.geometry.spheremic.computeOffset(line.getPath().getAt(0),20000000,lineHeading);
line.getPath().insertAt(0,newPt0);
var newPt1=google.maps.geometry.spheremic.computeOffset(line.getPath().getAt(1),20000000,lineHeading+180);
line.getPath().push(newPt1);
}
google.maps.event.addDomListener(窗口“加载”,initMap)代码>
html,
身体,
#地图{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}