Home › Forums › Feature Requests › Access country from a Google Maps geocoding request
Hi Elliot,
I am using the Google Maps field in the backend to geocode some addresses. However, the result set does not include a country but only the fully formatted address.
I would find it really helpful if the whole response object was available for processing because it contains more information I could and would like act on.
Ok, I found out how to do this myself. It requires the following changes and I’d be glad to have them added.
In acf-input.js #5307:
$.each(location.address_components,function(key,item){
if (item.types[0] == 'country') {
acf.val( self.$el.find('.input-country'),item.short_name);
}
});
Another change goes to google-map.php #84 ,the array gets one more entry after lang
:
'country' => ''
These small changes add the short_name of the country to the saved data.
Hi @wloske
You can always add the script by using the acf/input/admin_footer and then add a new text field to hold the country name. Please take a look at this page to learn how to work with ACF and Javascript: https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/.
If you still want to have the country field added to the core files, please open a new ticket so your suggestion can be passed directly to the plugin author. You can open a new ticket here: https://support.advancedcustomfields.com/new-ticket.
I hope this helps 🙂
Hi James,
thanks for pointing this possibility out. How would I be able to act upon a geocoding request. As far as I can see the geocoder response is not available to me when the script is loaded and no event is being fired to get hold of that response object. But I might have overseen something.
Best
Wolfgang
Hi @wloske
I believe you need to execute it only when the page is loaded like this:
<script type="text/javascript">
(function($) {
// execute the code when the page is loaded
$(document).ready(function(){
// Your code here
});
})(jQuery);
</script>
Sometimes, you also need to watch the newly created element by using the on()
function. This page should give you more idea about it: http://stackoverflow.com/questions/6658752/click-event-doesnt-work-on-dynamically-generated-elements.
Hope this helps 🙂
The topic ‘Access country from a Google Maps geocoding request’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.