如何计算纬度和经度指定的两点之间的距离?
为了澄清,我想要以公里为单位的距离; 这些要点使用WGS84系统,我想了解可用方法的相对准确性.
我目前正在使用下面的功能,但它无法正常工作.根据谷歌地图,这些坐标(从59.3293371,13.4877472到59.3225525,13.4619422)之间的距离是2.2公里,而函数返回1.6公里.如何使此功能返回正确的距离?
function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1); // deg2rad below
var dLon = deg2rad(lon2-lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km
return d;
}
function deg2rad(deg) {
return deg * …Run Code Online (Sandbox Code Playgroud) 我找到了几个node.js模块,用于使用ip地址查找有关客户端位置和网络的信息.
要求:
位置 - 国家,城市,州,纬度,经度等
网络 - 互联网服务提供商,互联网连接类型和互联网速度等
数据准确性 - 最大可能性.
注意:寻找服务器端解决方案.
上述模块使用maxmind数据.我也读过有关maxmind数据准确性的文章.
我很困惑选择上面的node.js模块,我想知道是否有更好的node.js框架可用于查找符合我要求的信息或任何其他可以移植到node.js的语言插件.
任何想法都会很棒.
如何使用node.js找到两个地理点之间的距离(经度和经度集)
我使用谷歌地图距离矩阵服务在客户端javascript中的代码.
我想在serversidejavascript(在node.js router.js或datamodel.js中)做同样的事情.
我的客户端Javascript代码:
function calculateDistances() {
var gs =require('googlemaps');
var latlong = { 'latitude': 52.5112, 'longitude': 13.45155};
var origin1 = gs.LatLng(13.125511084202,80.029651635576);
var origin2 = new google.maps.LatLng(12.9898593006481,80.2497744326417);;
var destinationA = new google.maps.LatLng(13.125511084202,80.029651635576);;
var destinationB = new google.maps.LatLng(12.9898593006481,80.2497744326417);
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin1, origin2],
destinations: [destinationA, destinationB],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.METRIC,
avoidHighways: false,
avoidTolls: false
}, callback);
}
function callback(response, status) {
if (status != google.maps.DistanceMatrixStatus.OK) {
alert('Error was: ' + status);
} else {
var …Run Code Online (Sandbox Code Playgroud) node.js ×2
algorithm ×1
coordinates ×1
distance ×1
geolocation ×1
google-maps ×1
haversine ×1
ip ×1
javascript ×1
maps ×1
math ×1
maxmind ×1
node-modules ×1