Reputation: 161
I'm trying to use the Google Roads API to find the GPS coordinates of the closest point on a road from a given point. It only completes the request for the first given point ("originalIndex": 0
); can anyone explain why? My API key is valid, and I can locate the second point on Google Maps and see a nearby road. When I request the second point by itself, I receive the empty response "{}".
Request:
Response:
{"snappedPoints": [
{
"location": {
"latitude": 54.9702813818773,
"longitude": -1.6113525033160663
},
"originalIndex": 0,
"placeId": "ChIJicwBW7ZwfkgRQJjXzwd96mM"
},
{
"location": {
"latitude": 54.9702813818773,
"longitude": -1.6113525033160663
},
"originalIndex": 0,
"placeId": "ChIJicwBW7ZwfkgRQZjXzwd96mM"
}]}
Upvotes: 1
Views: 543
Reputation: 32110
The distance between your point and the road should be within 50-60 meters. If this distance is bigger the service returns empty response.
In your example the point -0.030331,30.513929
is far away. You can check it with geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D-0.030544%252C30.514678
You will see that distance is bigger than 50 meters.
If I select a point closer to the road, for example -0.027619,30.51668
, the nearest road endpoint will return results
https://roads.googleapis.com/v1/nearestRoads?points=-0.027619%2C30.51668&key=YOUR_API_KEY
The similar issue was reported before in the public issue tracker:
https://issuetracker.google.com/issues/37843707
I hope this addresses your doubt.
Upvotes: 3
Reputation: 161324
The second point (-0.030331,30.513929) is too far from the road. In that case the API the documentation says it will return an empty response ("If there are no nearby roads, no segment is returned.")
Upvotes: 1