Google maps api - snap marker to nearest road
Use the directions service. Get driving directions from the point of interest to the point of interest. Should be on the road.
var directionsService = new google.maps.DirectionsService();
directionsService.route({origin:homeLatlng, destination:homeLatlng, travelMode: google.maps.DirectionsTravelMode.DRIVING}, function(response, status) {
if (status == google.maps.DirectionsStatus.OK)
{
var homeMarker = new google.maps.Marker({
position: response.routes[0].legs[0].start_location,
map: map,
title: "Check this cool location",
icon: image,
shadow: shadow
});
} else {
var homeMarker = new google.maps.Marker({
position: homeLatlng,
map: map,
title: "Check this cool location",
icon: image,
shadow: shadow
});
}
});
example