So I am trying to do a project for work where I create a matrix where the x-axis is a list of stores and the y axis is another list of stores and the values are the distances returned see the link below for an example of what im looking for
Example Output
This is the code I am running with dummy addresses for lst_stores1 and lst_stores2
INPUT:
import googlemaps
lst_store1 = ['777 Brockton Avenue, Abington MA 2351',
'30 Memorial Drive, Avon MA',
'250 Hartford Avenue, Bellingham MA',
'700 Oak Street, Brockton MA',
'591 Memorial Dr, Chicopee MA']
lst_store2 = ['55 Brooksby Village Way, Danvers MA',
'137 Teaticket Hwy, East Falmouth MA',
'42 Fairhaven Commons Way, Fairhaven MA',
'374 William S Canning Blvd, Fall River MA',
'121 Worcester Rd, Framingham MA']
my_dist = gmaps.distance_matrix(lst_store1,lst_store2)
print(my_dist)
OUTPUT:
'destination_addresses': ['55 Brooksby Village Dr, Danvers, MA 01923, USA', '137 Teaticket Hwy, Teaticket, MA 02536, USA', '42 Fairhaven Commons Way, Fairhaven, MA 02719, USA', '374 William S Canning Blvd, Fall River, MA 02721, USA', '121 Worcester Rd, Framingham, MA 01701, USA'], 'origin_addresses': ['777 Brockton Ave, Abington, MA 02351, USA', '30 Memorial Dr, Avon, MA 02322, USA', '250 Hartford Ave, Bellingham, MA 02019, USA', '700 Oak St, Brockton, MA 02301, USA', '591 Memorial Dr, Chicopee, MA 01020, USA'], 'rows': [{'elements': [{'distance': {'text': '65.0 km', 'value': 65015}, 'duration': {'text': '1 hour 4 mins', 'value': 3860}, 'status': 'OK'}, {'distance': {'text': '89.0 km', 'value': 89014}, 'duration': {'text': '1 hour 14 mins', 'value': 4437}, 'status': 'OK'}, {'distance': {'text': '72.4 km', 'value': 72367}, 'duration': {'text': '56 mins', 'value': 3339}, 'status': 'OK'}, {'distance': {'text': '63.4 km', 'value': 63418}, 'duration': {'text': '51 mins', 'value': 3034}, 'status': 'OK'}, {'distance': {'text': '58.7 km', 'value': 58690}, 'duration': {'text': '50 mins', 'value': 2998}, 'status': 'OK'}]}, {'elements': [{'distance': {'text': '62.6 km', 'value': 62649}, 'duration': {'text': '53 mins', 'value': 3189}, 'status': 'OK'}, {'distance': {'text': '96.8 km', 'value': 96832}, 'duration': {'text': '1 hour 5 mins', 'value': 3889}, 'status': 'OK'}, {'distance': {'text': '70.4 km', 'value': 70413}, 'duration': {'text': '46 mins', 'value': 2788}, 'status': 'OK'}, {'distance': {'text': '61.5 km', 'value': 61463}, 'duration': {'text': '41 mins', 'value': 2483}, 'status': 'OK'}, {'distance': {'text': '50.5 km', 'value': 50512}, 'duration': {'text': '38 mins', 'value': 2273}, 'status': 'OK'}]}, {'elements': [{'distance': {'text': '95.3 km', 'value': 95321}, 'duration': {'text': '1 hour 2 mins', 'value': 3702}, 'status': 'OK'}, {'distance': {'text': '115 km', 'value': 115239}, 'duration': {'text': '1 hour 14 mins', 'value': 4436}, 'status': 'OK'}, {'distance': {'text': '90.2 km', 'value': 90161}, 'duration': {'text': '57 mins', 'value': 3427}, 'status': 'OK'}, {'distance': {'text': '81.2 km', 'value': 81211}, 'duration': {'text': '52 mins', 'value': 3122}, 'status': 'OK'}, {'distance': {'text': '39.8 km', 'value': 39785}, 'duration': {'text': '29 mins', 'value': 1710}, 'status': 'OK'}]}, {'elements': [{'distance': {'text': '65.5 km', 'value': 65521}, 'duration': {'text': '55 mins', 'value': 3323}, 'status': 'OK'}, {'distance': {'text': '91.4 km', 'value': 91450}, 'duration': {'text': '1 hour 2 mins', 'value': 3726}, 'status': 'OK'}, {'distance': {'text': '65.0 km', 'value': 65031}, 'duration': {'text': '44 mins', 'value': 2625}, 'status': 'OK'}, {'distance': {'text': '56.1 km', 'value': 56081}, 'duration': {'text': '39 mins', 'value': 2320}, 'status': 'OK'}, {'distance': {'text': '53.4 km', 'value': 53385}, 'duration': {'text': '40 mins', 'value': 2407}, 'status': 'OK'}]}, {'elements': [{'distance': {'text': '168 km', 'value': 167923}, 'duration': {'text': '1 hour 43 mins', 'value': 6187}, 'status': 'OK'}, {'distance': {'text': '227 km', 'value': 227118}, 'duration': {'text': '2 hours 17 mins', 'value': 8217}, 'status': 'OK'}, {'distance': {'text': '183 km', 'value': 183401}, 'duration': {'text': '1 hour 54 mins', 'value': 6818}, 'status': 'OK'}, {'distance': {'text': '163 km', 'value': 163452}, 'duration': {'text': '1 hour 43 mins', 'value': 6170}, 'status': 'OK'}, {'distance': {'text': '112 km', 'value': 112386}, 'duration': {'text': '1 hour 10 mins', 'value': 4196}, 'status': 'OK'}]}], 'status': 'OK'}
I'm having trouble deciphering the output it's returning and figuring out how to convert it into the format I described above.
P.S. I have imported the appropriate libraries and set up my API key etc it is being referenced in a different cell in jupyter