I\'m trying to snap coordinate to nearest road. But still I can\'t do that in simple way.
This is simple code, how to improve it that result would be marker on the 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