gpt4 book ai didi

javascript - 在javascript中查找中间纬度和经度

转载 作者:行者123 更新时间:2023-11-29 14:49:14 26 4
gpt4 key购买 nike

我有以下数据。1.来源​​名称。2.目的地名称。我需要在从源到目的地的路径上找到经纬度对。有可用的谷歌 Api 吗??。我提到了这个问题Finding intermediate Lattitude Longitude between two given points但无法理解整个事情。任何人都可以对此有更简单的答案吗?

编辑这是我尝试过的

 //store lat and long
var sd_array=[];
$('#processbtn').click(function(e){
//get source and destination name
var source=$('#source').val();
var destination=$('#destination').val();
if(source==''||destination==''){
alert("all fields required");
}else{
//decode lat-long from address
getLatitudeAndLongitude(source);
getLatitudeAndLongitude(destination);
}
});
function getLatitudeAndLongitude(address){
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
//store to array
sd_array.push(latitude);
sd_array.push(longitude);
}
});
}
function getInterMediateLatLong(sd_array){
//get intermediate locations
/*sd_array[0] source lat
sd_array[1] source long
sd_array[2] destination lat
sd_array[3] destination long*/
}

我需要帮助才能获得中间位置。

最佳答案

首先你要明白这是一个Mathematical problem ,但是很简单。 Google 会返回一组 o XY 点...过程是:

  1. 正确表达“引用点”SDS源和D 终点。所以 Sx,Sy,Dx,Dy。它们不是“名称”,而是 XY 编码 (!)。

  2. 检查如何向 Google-API 说明您需要多少积分

  3. 向 Google-API 提交您的查询:编辑您的问题以向我们显示您的查询(Javascript 代码)!我们可以在这里讨论它们。


你需要表达

{path[]: LatLngPathes, samples: 4}

获取LatLngPathes的Javascript片段示例:

 var source = new google.maps.LatLng(36.578581, -118.291994);
var destination = new google.maps.LatLng(36.606111, -118.062778);

关于javascript - 在javascript中查找中间纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28524163/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com