I am new to JSON, Google Maps APIs DistanceMatrix & Places
I am trying to display results from two different JSON Results
Basically both of them come from two different "lists"
edit
for object_json
i am getting all the nearby places from my coordinates, I will then get the places_id of each result and use it to query the distance-matrix api and get each of distances object_json2
Code
#name and types from Places API
lines = (f"{s['name']}: {', '.join(r.replace('_', ' ') for r in s['types'])} -" for s in object_json['results'][0:5])
#distance from DistanceMatrix API
lines2 = (f"{t['distance']['text']}" for t in item['elements'] for item in object_json2['rows'])
Sample JSON object_json: getting the name, types and places_id
"results" : [
{
"name" : "Joe’s Thai Kitchen",
"place_id" : "ChIJIadbw8sb2jER3i-OvZSCBGk",
"types" : [ "restaurant", "food", "point_of_interest", "establishment" ],
},
object_json2 based on the nearby search results, it will get the places_id and get the distance matrix results for each elements distance.
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "0.3 km",
"value" : 303
},
"duration" : {
"text" : "2 mins",
"value" : 123
},
"status" : "OK"
},
{
"distance" : {
"text" : "90 m",
"value" : 90
},
"duration" : {
"text" : "1 min",
"value" : 36
},
"status" : "OK"
}
]
}
],
First two results
Joe’s Thai Kitchen: restaurant, food, point of interest, establishment - ['0.4 km', '77 m', '0.3 km', '0.8 km', '0.3 km']
Hong Kong Street Chun Kee: restaurant, food, point of interest, establishment - ['0.4 km', '77 m', '0.3 km', '0.8 km', '0.3 km']
Desired first two results
Joe’s Thai Kitchen: restaurant, food, point of interest, establishment - 0.4 km
Hong Kong Street Chun Kee: restaurant, food, point of interest, establishment - 77 m
Hope somebody can help thank you.