我正在使用 TomTom 反向地理编码 API 根据给定的纬度和经度获取地址。但是,我注意到返回的地址可能并不总是准确匹配。有没有办法确定以米为单位的准确率或找出地理编码结果距提供的位置有多远?我想评估地理编码结果的精度。任何见解或建议将不胜感激。”
运行: 纬度的反向地理编码响应:19.067862939388316,经度:73.01974981192562 {"summary":{"queryTime":19,"numResults":1},"addresses":[{"address":{"routeNumbers":[],"street":"Thane Belapur Road","streetName" :"Thane Belapur Road","countryCode":"IN","countrySubdivision":"马哈拉施特拉邦","countrySecondarySubdivision":"Thane","municipality":"Navi Mumbai","postalCode":"400703","municipalitySubdivision ":"MIDC 工业区","country":"印度","countryCodeISO3":"IND","freeformAddress":"Thane Belapur Road, MIDC 工业区, 新孟买 400703, 马哈拉施特拉邦","boundingBox":{"东北":"19.068174,73.019439","西南":"19.067217,73.019397","实体":"位置"},"countrySubdivisionName":"马哈拉施特拉邦","countrySubdivisionCode":"MH","localName":"Navi孟买"},"位置":"19.067846,73.019417","id":"DB-3I8pDDsYD5PtGxvzj6g"}]} 构建成功(总时间:4秒)
欢迎来到 Stack Overflow!
您可以使用Haversine Formula来计算两组坐标之间的距离。因此,将提供的位置与返回的位置进行比较。
这是一个伪代码示例:
function calculateDistance(lat1, lon1, lat2, lon2):
# Convert latitude and longitude from degrees to radians
lat1_rad = convertDegreesToRadians(lat1)
lon1_rad = convertDegreesToRadians(lon1)
lat2_rad = convertDegreesToRadians(lat2)
lon2_rad = convertDegreesToRadians(lon2)
# Earth's radius in meters
R = 6371000.0
# Difference in coordinates
delta_lat = lat2_rad - lat1_rad
delta_lon = lon2_rad - lon1_rad
# Apply Haversine formula
a = sin(delta_lat / 2) * sin(delta_lat / 2) +
cos(lat1_rad) * cos(lat2_rad) *
sin(delta_lon / 2) * sin(delta_lon / 2)
c = 2 * atan2(sqrt(a), sqrt(1 - a))
# Distance in meters
distance = R * c
return distance
function convertDegreesToRadians(degrees):
return degrees * (π / 180)
# Example usage
lat1 = 40.7128 # Latitude of New York City
lon1 = -74.0060 # Longitude of New York City
lat2 = 51.5074 # Latitude of London
lon2 = -0.1278 # Longitude of London
distance = calculateDistance(lat1, lon1, lat2, lon2)
print("Distance: ", distance, " meters")
我希望这能解决您的问题。