My Google Map needs to support “off road” locations.
I’d like to know how to prevent my map marker from snapping to road.
Address is passed from an input field and lat & lng are extracted form marker’s position.
function geoCodeLocation(address, lat, lng) {
geocoder.geocode(
{
"address" : address ? address : '',
"location" : new google.maps.LatLng(lat, lng)
},
/* ... */
}
The code you have shown is pretty minimal, so I may have missed the point, but Geocoding normally does one of two things:
The GeocodingService requires either the address or the location, but not both.
Your code looks like it always expects to have the LatLng and that the address may exist. If you call the Geocoder with a LatLng, it will return an address. In that case, it makes sense that a marker would be attached to the road.
On the other hand, if you have an address, the LatLng you get back will be based on the address, so it also makes sense that it will be attached to the road.
But if you always have the LatLng, why not just create the marker with the LatLng and skip the geocode call (especially since you don’t want the marker to be on the road)?
If I am off the mark, could you please add more detail to your question?