Juliatzin
Juliatzin

Reputation: 19695

See if marker is not on a Street in google map

Is it posible to know if a position (lat / lng) is in a street? I would like to disable a marker when it is not inserted by user in a street ( in a forest, etc...)

Upvotes: 2

Views: 97

Answers (1)

MaciejGórski
MaciejGórski

Reputation: 22232

Based on the LatLng user has given you, you may query Google Directions API for the nearest "on the road" position like this:

http://maps.googleapis.com/maps/api/directions/json?origin=51,19&destination=51,19&sensor=false (origin and destination is the same)

You will then get some value like

           "lat" : 50.9984526,
           "lng" : 19.0049844

in few places in response, which should generaly be all the same everywhere.

Now calculate the distance between the value user gives you and what Directions API returned, and if it is less than X meters, assume you are on the road.

Upvotes: 1

Related Questions