0 purchases
coordinate calculator
CoordinateCalculator #
公式计算引自 http://edwilliams.org/avform147.htm#Intro
Use #
/// pubspec.yaml
coordinate_calculator:
git:
url: https://github.com/DeliriousLee/CoordinateCalculator.git
/// main.dart
import 'package:coordinate_calculator/coordinate_calculator.dart';
/// calculate result: km
/// 计算结果:km
var result = DLCoordinateManager.kilometersDistanceFrom(
lat1: double.parse(_originLatitude.text),
long1: double.parse(_originLong.text),
lat2: double.parse(_destLatitude.text),
long2: double.parse(_destLong.text));
copied to clipboard
Example #
上海虹桥机场 到 北京首都国际机场 直线距离
Python #
locationCalculator.py
附带了python版本的计算公式
#
# @desc : python 版本的公式计算
# @file : locationCalculator.py
# @date : 23/02/07 11:47
#
import math
Earth_Radius=6378.137
def sin_square(a):
result=math.sin(a)
return result*result
def rad(ang):
return math.pi*ang/180.0
#a,b参数是数组
def distance_calculate(a,b):
lata,lnga=a[0],a[1]
latb,lngb=b[0],b[1]
radlata,radlnga=rad(lata),rad(lnga)
radlatb, radlngb = rad(latb), rad(lngb)
#纬度差
minus_a=radlata-radlatb
#经度差
minus_b=radlnga-radlngb
return 2*math.asin( math.sqrt(sin_square(minus_a/2) + math.cos(radlata)*math.cos(radlatb)*sin_square(minus_b/2)))*Earth_Radius
copied to clipboard
大圆公式 #
the great circle fromula reference from http://edwilliams.org/avform147.htm#Intro
Distance between points
The great circle distance d between two points with coordinates {lat1,lon1} and {lat2,lon2} is given by:
d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2))
copied to clipboard
A mathematically equivalent formula, which is less subject to rounding error for short distances is:
d=2*asin(sqrt((sin((lat1-lat2)/2))^2 +
cos(lat1)*cos(lat2)*(sin((lon1-lon2)/2))^2))
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.