googlemaps / google-maps-services-python

Python client library for Google Maps API Web Services
Apache License 2.0
4.56k stars 1.31k forks source link

Distance Matrix API: Erroneous result - Need help on a fix #488

Closed tle4336 closed 1 year ago

tle4336 commented 1 year ago
  1. I am using the googlemaps package in Python (Environment: IDE - Pycharm 2021.3 version, OS - Windows 10 Pro 64-bit) to call the function distance_matrix. The result, in miles, returned from this function between the origin = ['925 Highway 124,Braselton,GA'] and destination = ['4880 Highway 129 N,Jefferson,GA'] as input is quite erroneous, 208.098 miles

Code example

import googlemaps
gmaps = googlemaps.Client(key=[My_Api_key])
origins = ['925 Highway 124,Braselton,GA']
destinations = ['4880 Highway 129 N,Jefferson,GA'] 
gmaps_distance = gmaps.distance_matrix(origins=origins,
                                                                    destinations=destinations, mode = 'bicycling')
gmaps_distance['rows'][0]['elements'][number_of_destinations]['distance']["value"] / 1609

Result is 208.098 miles, which is way above what Google Maps give us (13.3 miles, as shown here: https://www.google.com/maps/dir/925+GA-124,+Braselton,+GA+30517/Quality+Inn+Jefferson+at+I-85,+4880+US-129,+Jefferson,+GA+30549/@34.1286657,-83.800025,12z/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x88f5ef27e1292c33:0x6b8ffea60a1ceb78!2m2!1d-83.8037487!2d34.0976538!1m5!1m1!1s0x88f5e325a971e75d:0x605e6565ea5572ee!2m2!1d-83.6427945!2d34.1535394!3e1).

Could you please help look into this issue and let me know how we can circumvent this?

wangela commented 1 year ago

If you would like to upvote the priority of this issue, please comment below or react with :+1: so we can see what is popular when we triage.

@tle4336 Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

tle4336 commented 1 year ago

@amuramoto @wangela Can either of you please help look into the issue above? I found that it was due to the input "destination address" was auto-corrected (particularly the "city" field). Another case could be shown in the attached file, where the input destinations = ['1583 S East Rd,Farmington,CT']. After calling dist=gmaps.distance_matrix(origins, destinations, mode='bicycling') and tried to print out dist, I saw that the returning destination_addresses = ['S East Rd, New Hartford, CT 06057, USA']. This led to a very incorrect result of 30679 meters (~19.06 miles), compared to 11.9 miles by Google Maps. distance-1 distance-2 distance-3

amuramoto commented 1 year ago

This appears to be an issue with the underlying API. Please open at bug report in the public issue tracker

tle4336 commented 1 year ago

@amuramoto Thank you very much for your feedback. I already opened the issue there, but one thing i did notice was the change in address input. Is that really because of the API? I thought this is partially caused by the googlemaps package, no?