Using the Google Maps API, it is possible to retrieve travel distances and times between a number of points. They are received by Stata in the json-format, which can be read by the Stata-routine insheetjson.
I managed to read out the first two variables:
However, as the structure has some complexity, I did not manage to read the distance and duration.
I guess that this has to do with the fact that the distance and duration values are in an array, as it is possible to compute multiple trips, and consequently more distances and durations.
Any help would be appreciated.
Thanks
Kees
I managed to read out the first two variables:
Code:
tempvar destinationaddresses tempvar originaddresses cap gen str50 `destinationaddresses' = "" cap gen str50 `originaddresses' = "" copy "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Paris&destinations=Berlin" "test_googleapi.txt", replace insheetjson `destinationaddresses' `originaddresses' using "test_googleapi.txt", /// col("destination_addresses" "origin_addresses") replace display `destinationaddresses' display `originaddresses'
I guess that this has to do with the fact that the distance and duration values are in an array, as it is possible to compute multiple trips, and consequently more distances and durations.
Code:
tempvar distancevalue durationvalue cap gen str20 `distancevalue' = "" cap gen str20 `durationvalue' = "" copy "https://maps.googleapis.com/maps/api/distancematrix/json?origins=Paris&destinations=Berlin" "test_googleapi.txt", replace insheetjson `distancevalue' `durationvalue' using "test_googleapi.txt", /// col("rows:elements:distance:value" "rows:elements:duration:value") replace display `distancevalue' display `durationvalue'
Thanks
Kees