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.
01 | $(document).ready( function () { |
02 | var s = document.createElement( 'script' ); |
03 | s.id = "external_content" ; |
04 | s.async = true ; |
05 | s.src = "http://maps.google.com/maps/api/js?key=API_KEY_HERE" ; |
06 | document.getElementsByTagName( 'head' )[0].appendChild(s); |
07 | s.onload = function () { |
08 | var geocoder = new google.maps.Geocoder(); |
09 | var address = "ADDRESS_GOES_HERE" ; |
10 |
11 | geocoder.geocode( { 'address' : address}, function (results, status) { |
12 |
13 | if (status == google.maps.GeocoderStatus.OK) { |
14 | var longlat = results[0].geometry.location; |
15 | alert(longlat); |
16 | } |
17 | }); |
18 | } |
19 | |
20 | }); |
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
01 | $(document).ready( function () { |
02 | var s = document.createElement( 'script' ); |
03 | s.id = "external_content" ; |
04 | s.async = true ; |
05 | s.src = "https://maps.googleapis.com/maps/api/js?key=API_KEY_HERE" ; |
06 | document.getElementsByTagName( 'head' )[0].appendChild(s); |
07 | s.onload = function () { |
08 | var geocoder = new google.maps.Geocoder(); |
09 | var address = "ADDRESS_GOES_HERE" ; |
10 |
11 | geocoder.geocode( { 'address' : address}, function (results, status) { |
12 |
13 | if (status == google.maps.GeocoderStatus.OK) { |
14 | var longlat = results[0].geometry.location; |
15 | alert(longlat); |
16 | } |
17 | }); |
18 | } |
19 | |
20 | }); |
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.