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_Google Maps Api 3 - Fatal编程技术网

Javascript 使用从第一个点移动的距离计算两点之间的坐标

Javascript 使用从第一个点移动的距离计算两点之间的坐标,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我试图得到a点和b点之间当前位置的地理位置坐标,只知道从a点出发的距离,假设用户走直线 var disatnce_travelled = 375; //miles function initialize() { var locations = new Array(new google.maps.LatLng(40.7142700, -74.0059700),new google.maps.LatLng(43.585278, 39.720278)); var bounds = new google

我试图得到a点和b点之间当前位置的地理位置坐标,只知道从a点出发的距离,假设用户走直线

var disatnce_travelled = 375; //miles
function initialize() {
var locations = new Array(new google.maps.LatLng(40.7142700, -74.0059700),new google.maps.LatLng(43.585278, 39.720278));
var bounds = new google.maps.LatLngBounds();
for(i in locations)
    bounds.extend(locations[i]);
var mapOptions = {
 zoom: 3,
 center: bounds.getCenter(),
 mapTypeId: google.maps.MapTypeId.TERRAIN
};

var map = new google.maps.Map(document.getElementById('map-canvas'),
   mapOptions);

var flightPlanCoordinates = locations;
var flightPath = new google.maps.Polyline({
 path: flightPlanCoordinates,
 strokeColor: '#7f3f98',
 strokeOpacity: 1.0,
 strokeWeight: 2
});

flightPath.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
该方法具有插值方法
返回LatLng,该LatLng位于起始LatLng和目标LatLng之间的给定部分。

然而,这似乎是沿着测地线路径插值的

一种选择是使用的v3端口


var距离_=375//英里
函数初始化(){
var locations=新数组(新的google.maps.LatLng(40.7142700,-74.0059700),新的google.maps.LatLng(43.585278,39.720278));
var bounds=new google.maps.LatLngBounds();
适用于(i个地点)
扩展(位置[i]);
变量映射选项={
缩放:2,
center:bounds.getCenter(),
mapTypeId:google.maps.mapTypeId.TERRAIN
};
var map=new google.maps.map(document.getElementById('map-canvas'),
地图选项);
var FlightPlan坐标=位置;
var flightPath=new google.maps.Polyline({
路径:FlightPlan坐标,
strokeColor:“#7f3f98”,
笔划不透明度:1.0,
冲程重量:2
});
flightPath.setMap(map);
var marker=new google.maps.marker({
位置:flightPath.GetPointAtDistance(飞行距离*1609.34),
map:map});
}
google.maps.event.addDomListener(窗口“加载”,初始化);

发布您编写的代码,并解释您遇到的问题。这不是问题。到目前为止已使用我的代码更新。我想画出用户在位置[0]和位置[1]之间的位置,知道Distance_Traveled您是否假设用户在点之间沿直线移动?有插值方法
返回LatLng,该LatLng位于起始LatLng和目标LatLng之间的给定部分。
1609.34代表什么
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false&libraries=geometry"></script>
<script src="scripts/v3_epoly.js"></script>
<script>
var distance_travelled = 375; //miles
function initialize() {
var locations = new Array(new google.maps.LatLng(40.7142700, -74.0059700),new google.maps.LatLng(43.585278, 39.720278));
var bounds = new google.maps.LatLngBounds();
for(i in locations)
    bounds.extend(locations[i]);
var mapOptions = {
 zoom: 2,
 center: bounds.getCenter(),
 mapTypeId: google.maps.MapTypeId.TERRAIN
};

var map = new google.maps.Map(document.getElementById('map-canvas'),
   mapOptions);

var flightPlanCoordinates = locations;
var flightPath = new google.maps.Polyline({
 path: flightPlanCoordinates,
 strokeColor: '#7f3f98',
 strokeOpacity: 1.0,
 strokeWeight: 2
});

flightPath.setMap(map);
var marker = new google.maps.Marker({
   position: flightPath.GetPointAtDistance(distance_travelled*1609.34),
   map:map});
}

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