i want to know accuracy of the geocoding results

79 Views Asked by At

I am using the TomTom Reverse Geocoding API to obtain an address based on a given latitude and longitude. However, I've noticed that the returned address may not always be an accurate match. Is there a way to determine the accuracy rate in meters or find out how far the geocoded result is from the provided location? I would like to assess the precision of the geocoding results. Any insights or suggestions would be appreciated."

run: Reverse Geocoding Response for Latitude: 19.067862939388316, Longitude: 73.01974981192562 {"summary":{"queryTime":19,"numResults":1},"addresses":[{"address":{"routeNumbers":[],"street":"Thane Belapur Road","streetName":"Thane Belapur Road","countryCode":"IN","countrySubdivision":"Maharashtra","countrySecondarySubdivision":"Thane","municipality":"Navi Mumbai","postalCode":"400703","municipalitySubdivision":"MIDC Industry Area","country":"India","countryCodeISO3":"IND","freeformAddress":"Thane Belapur Road, MIDC Industry Area, Navi Mumbai 400703, Maharashtra","boundingBox":{"northEast":"19.068174,73.019439","southWest":"19.067217,73.019397","entity":"position"},"countrySubdivisionName":"Maharashtra","countrySubdivisionCode":"MH","localName":"Navi Mumbai"},"position":"19.067846,73.019417","id":"DB-3I8pDDsYD5PtGxvzj6g"}]} BUILD SUCCESSFUL (total time: 4 seconds)

1

There are 1 best solutions below

2
Severin On

Welcome to Stack Overflow!

You can use the Haversine Formula to calculate the distance between two sets of coordinates. So compare the provided location with the returned location.

Here is a pseudocode example:

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") 
# -> "Distance: 5,570,222 meters

I hope this solves your problem.