No matter what I do, I haven’t been able to get Geolocation to do anything for my meta box fields. Auto-complete fields never pop up anything on a field with 'address' as the ID. And seemingly related, if I add a map field type, the post entry page shows the field map stuck on Dublin, and clicking the 'Find Address' button does nothing.
It feels like I’m missing something basic, since none of the geo-related functionality is activating for me. Sorry for asking what seems elementary.
In Chrome, I get this console error:
Uncaught TypeError: Cannot read property 'Autocomplete' of undefined at String.<anonymous> (mb-geo.js?ver=1.0.0:88) at Function.each (load-scripts.php?c=0&load=jquery-core,jquery-migrate,utils,moxiejs,plupload&ver=4.9.6:2) at Object.initAutoComplete (mb-geo.js?ver=1.0.0:83) at Object.init (mb-geo.js?ver=1.0.0:41) at mb-geo.js?ver=1.0.0:195 at mb-geo.js?ver=1.0.0:202
My function to generate the meta box is below, [API key intentionally obscured]
Well, I walked away for a couple hours and came back. Now, the address auto-complete functionality is magically working. I changed nothing. Perhaps something took a while to register with the Maps API.
The map field is still not working when I click on'Find Address'. And auto-complete on the 'address' field won't work if there is a map field added to the same metabox. But as long as I remove the map field, Geolocation autocomplete works on the 'address' field.
Now that it's working, I notice what seems to be a bug with Geolocation and autocomplete/autopopulate, at least according to what docs say. It seems that ANY field with an ID that contains 'address', even if the ID doesn't start with 'address' is treated as an auto-complete field. Because of this, any other field that contains address in the ID, such as another documented field ID of 'street_address' can’t get auto-populated.
See screenshot of my fields rendered on the post page. 'Location name' is 'id'=>'address', 'Address 1' is now 'id'=>'street_address', and 'Address 2' is now 'id'=>'street_address2'. Note how street_address and street_address2 contain placeholder text of 'Enter a location'
I've worked with the map field and Geolocation in the last couple of days and made some improvements. I've just released a new version of Geolocation extension with a better compatibility with the
map field. Previously both Geolocation and
map field try to enqueue their own Google Maps scripts, which causes some kind of conflict. This conflict was fine until recently, it prevents some autocomplete for the address field.
Can you please update it or the Meta Box AIO and let me know how it goes?
Regarding the "Find Address" button, I also added some small improvements if the
map is inside a group. The change is not in the new version of Meta Box yet. It's on Github and you can download it here:
I'm making some other improvements and will release new version of Meta Box when they're done.
I updated Geolocation. Auto-complete seems to work fine now, even if a map field is added to the meta box. Just need to make sure I added the API key again in the map field's settings, even though it's already applied to via the meta box.
Find Address still doesn't seem to do anything when clicked for me. Not sure why.
Did you see my buried bug report in the second followup message about a field that contains the word 'address' anywhere triggering auto-complete fields, even if not starting with 'address'? It prevents a field like 'street_address' from being auto-populated. Apologies for adding two issues in one thread.
I've tried to test with 2 addresses and the auto complete works for both. This is the screenshot:
"Find Address" also works for me. Maybe I'm using the latest code of the Meta Box plugin on Github. Have you tried it?
I think maybe I wasn't clear enough in what I was reporting about 'address' fields. Separate issue from not getting auto-complete to work...
In the bug report, I wasn't noting that certain fields wouldn’t auto-complete. But rather, that fields with 'address' in the name would not auto-populate.
For example, in your screenshot, apply an ID of 'address' to the field labeled 'Location name' (and intend on using that as the auto-complete field), then use ID of 'street_address' for the field labeled 'Address 1'. ('Address 2' in my screenshot is just an extra freeform field we sometimes need to us in the US for apartment #, floor, PO box #, etc.)
Now, you'll notice when you fill in a name or address in the Location name field, that 'street_address' does not get auto-completed with the specific street address.
My expectation is that 'address' will auto-complete with a full address, for example:
'660 3rd Street, San Francisco, CA, USA'.
And with that address, 'street_address' should get auto-populated with '660 3rd Street', 'locality' with 'San Francisco', 'administrative_area_level_1_short' with 'CA', etc.
'street_address' is the one that will not auto-populate, because it is being interpreted as an auto-complete field, not an auto-populate field. According to the docs, only fields with an ID that starts with 'address' will be treated as auto-complete, right?
Thanks a lot for your feedback.
There are 2 issues here:
array( 'id' => 'street_address', 'type' => 'text', 'name' => 'Street Address', 'binding' => 'street_number + " " + route', ),