Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccuracy in Distance Calculation Using Google Maps API with .NET 8.0 #386

Closed
AlexGall24 opened this issue Apr 10, 2024 · 5 comments
Closed

Comments

@AlexGall24
Copy link

Hello,

Firstly, I would like to extend my gratitude for your valuable contribution to the project.

During the course of my work, I have encountered a notable discrepancy in distance calculation that warrants your attention.

Environment Details:

.NET Core Framework Version: .NET 8.0
Google Maps API Version: 5.31

Issue Description:
We are currently working with the Google Maps Directions API to calculate walking distances between two points. However, the distances returned by the API seem to be significantly inaccurate. This issue does not trigger an error in the traditional sense, but the data accuracy is compromised, which is concerning.

Correct distance: 249 ft
Incorrect distance: 1.5 mi

API Request Details:
Here are the specifics of the request and the method involved:

Origin Coordinates: 32.5523936,-116.9080947
Destination Coordinates: 32.552406158844668,-116.90853506326675

The code snippet for generating the directions request is as follows:

DirectionsRequest request = new()
{
Key = _key,
TravelMode = TravelMode.Walking,
Origin = new LocationEx(Origin),
Destination = new LocationEx(Destination)
};

DirectionsResponse response = await GoogleMaps.Directions.QueryAsync(request);

Despite the proximity of the origin and destination points, the data fetched from the Google Maps Directions API is surprisingly off the mark.

Suspected Cause:
The inconsistency appears to be linked to the TravelMode enum, specifically when set to Walking, Driving Etc.

To better illustrate the issue, I have included comparison images showcasing the distance variations.

Request for Assistance:
Could you please review the implementation and advise on any potential misconfigurations or alternative approaches to address this accuracy problem? Your expertise in this matter would be immensely appreciated.

PS: I also tested the Routes, DirectionsMatrix with the QueryAsync and they also responded with the incorrect data.

Best regards

Response using GoogleAPI Library:
image

Response using Gmaps API with correct travelMode:
image

Response using Gmaps API with incorrect travelMode:
image

@vivet
Copy link
Owner

vivet commented Apr 10, 2024

Will take a look at it soon

@vivet
Copy link
Owner

vivet commented Apr 14, 2024

I took a look at it.
It seems the Google docs is incorrect for the enum. It needs to be in upper-case.
I will implement a fix within the next few days

@vivet
Copy link
Owner

vivet commented Apr 14, 2024

I actually got it finished already.
It's pushed and new NuGet 5.4.0 should be ready soon.

@AlexGall24
Copy link
Author

AlexGall24 commented Apr 15, 2024

Thank you very much !

This fixed the issue.

@AlexGall24
Copy link
Author

Closing issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants