Can we use the geolocation field to give us the latitude/longitude coordinates of a submitted address? When I try to give it a default value, the only option is geolocation, I want the default value to be an address and have the lat/long automatically populate. Is this possible?
Question
Question
Can geolocation tool be used to get coordinates of submitted address
asked on September 28, 2017
0
0
Replies
replied on September 28, 2017
Hey,
I don't believe you can pass an address and have the Geolocation field geocode it. That said you can achieve it with a call to the Google Map API. Keep in mind that there are limitations to this api, I cant remember exact numbers but I think you are limited to 2500 calls a day or something.
$(document).ready(function() { var s = document.createElement('script'); s.id = "external_content"; s.async = true; s.src = "http://maps.google.com/maps/api/js?key=API_KEY_HERE"; document.getElementsByTagName('head')[0].appendChild(s); s.onload = function() { var geocoder = new google.maps.Geocoder(); var address = "ADDRESS_GOES_HERE"; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var longlat = results[0].geometry.location; alert(longlat); } }); } });
You will need to get a api key from google. its free just have to login and request one.
Not exactly what you were after I know but this is the only way I know to get proper geocoding.
Hope it helps
2
0
replied on October 20, 2021
$(document).ready(function() { var s = document.createElement('script'); s.id = "external_content"; s.async = true; s.src = "https://maps.googleapis.com/maps/api/js?key=API_KEY_HERE"; document.getElementsByTagName('head')[0].appendChild(s); s.onload = function() { var geocoder = new google.maps.Geocoder(); var address = "ADDRESS_GOES_HERE"; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { var longlat = results[0].geometry.location; alert(longlat); } }); } });
For anybody trying this in 2021, here is the update version of this. Thank you Aaron for providing this originally!
1
0
You are not allowed to follow up in this post.