# Determine If GPS Coordinates Fall On A Road

## 01 December 2018 - 1 answer

I'm trying to determine whether a point is on a road/highway/freeway etc or in a building through a `Python` script. For some inputs they'll contain the user's velocity which means in some contexts, it'll be obvious given the device velocity. However, for instances when the user's instantaneous velocity is small it could be due to traffic, being stopped at lights etc.

I want to be able to input a pair of inputs, eg. `-33.852592, 151.210663` and receive a boolean result as to whether the user's coordinates fall on a road.

I've come across `Google places` and `OSRM` but haven't found a solution from these yet. Are there any other options I'm missing?

One option would be do do a DirectionsService.route request with the `origin` and `destination` set to the input point. That will return a 0 length route from the closest location on a road (within reason). If there are no results, the point isn't on the road. If you get a result, you can calculate the distance between your input and the point returned to make an informed decision about whether the coordinates are on the road or not.

Note that the GPS device itself may not be but so accurate.

proof of concept fiddle (with your example point)

code snippet:

``````var geocoder;
var map;

function initialize() {
var testPoint = {
lat: -33.852592,
lng: 151.210663
};
document.getElementById("map_canvas"), {
center: testPoint,
zoom: 22,
});
position: testPoint,
map: map,
icon: {
url: "https://maps.gstatic.com/intl/en_us/mapfiles/markers2/measle.png",
}
});

directionsService.route({
origin: testPoint,
destination: testPoint,
travelMode: "DRIVING"
}, function(result, status) {
if (status == 'OK') {
position: result.routes[0].legs[0].steps[0].start_location,
map: map,
icon: {
url: "https://maps.gstatic.com/intl/en_us/mapfiles/markers2/measle_blue.png",
}
});
if (distance < 10)
document.getElementById('info').innerHTML = "distance=" + distance + "m on road";
else
document.getElementById('info').innerHTML = "distance=" + distance + "m not on road";
});
}
``````html,
body {
height: 100%;
width: 100%;
margin: 0px;
``````<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry"></script>