Chrisjb / RDistanceMatrix

Builds isochrones using either the google distance matrix API or the Mapbox API. Contains functions to fetch the population and employment (England and Wales) within the isochrone.
Other
2 stars 0 forks source link

Error in Distance Matrix Request URL #1

Closed KHwong12 closed 3 years ago

KHwong12 commented 3 years ago

First of all, thanks for writing this package. I have been looking for scripts to generate isochrone maps with google map API for a long time.

When I tried to generate the isochrone polygon, the make_isochrone function fails. I checked the code and believe the error may be caused by the request URL to the google map Distance Matrix Service. Currently, it only allows 25 origins/destinations in a single request. (https://developers.google.com/maps/documentation/javascript/distancematrix)

But the request URL in distance_from_origins and distance_to_destinations is now requesting 100 points at one time. The functions return a list of NULL and thus make_isochrone fails to work. I am not sure why the line err <- httr::http_error(doc) does not throw an error though.

https://github.com/Chrisjb/RDistanceMatrix/blob/8aaf799a320afe04bc15b554ae2fe85a38f14c79/R/utils-isochrone.R#L51-L58

https://github.com/Chrisjb/RDistanceMatrix/blob/8aaf799a320afe04bc15b554ae2fe85a38f14c79/R/utils-isochrone.R#L108-L115

I changed the value 100 to 25 in my local machine and the functions work.

Chrisjb commented 3 years ago

Thanks for this. -seems Google has got a bit stricter on the use of this API. Changing to 25 fixes the issue as you say. Feel free to prepare a pull request if you like. Alternatively I can get to this a bit later on.

KHwong12 commented 3 years ago

Sure. I will prepare a PR.

I will add an additional argument max_dimension to the function, which should be the square of init_grid_size in the make_isochrone function.

Chrisjb commented 3 years ago

Sure. I will prepare a PR.

I will add an additional argument max_dimension to the function, which should be the square of init_grid_size in the make_isochrone function.

Thanks for the contribution, all looks good and have merged PR