Custom Fields
Re-Envisioned
Support Meta Box Geolocation Can't get Geolocation autocomplete to work, nor maps

This topic contains 6 replies, has 2 voices, and was last updated by  Anh Tran 1 year, 1 month ago.

  • Creator
    Topic
  • #10389
    Resolved
    Doug
    Participant

    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.

    I had Geolocation enabled via AIO. But since that didn’t seem to work, I deactivated that and manually installed the MB Geolocation plugin. I’ve applied my Google API key, and ensured the Maps JavaScript API is enabled in my Cloud Console. I also disabled all other plugins except for MB-related. I checked the wp-admin source, and map.js and mb-geo.js are both loaded.

    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]

    https://ghostbin.com/paste/52ut8

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #10390

    Doug
    Participant

    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’

    https://cl.ly/1u150h073l2r

    #10394

    Anh Tran
    Keymaster

    Hi Doug,

    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:

    https://github.com/wpmetabox/meta-box/

    I’m making some other improvements and will release new version of Meta Box when they’re done.

    #10402

    Doug
    Participant

    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.

    #10406

    Anh Tran
    Keymaster

    I’ve tried to test with 2 addresses and the auto complete works for both. This is the screenshot:

    View post on imgur.com

    “Find Address” also works for me. Maybe I’m using the latest code of the Meta Box plugin on Github. Have you tried it?

    #10408

    Doug
    Participant

    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?

    #10419

    Anh Tran
    Keymaster

    Hi Doug,

    Thanks a lot for your feedback.

    There are 2 issues here:

    • Auto-complete works for both address and street_address field (which doesn’t start with “address”). I’ve fixed this bug in the latest version, please update.
    • The street_address is not auto-populated: I spent hours reading the Google docs, while it clearly states that the street_address is supported, but all the examples are showing street_number and route only. I think you can use custom binding to get the street address part, like this:
    array(
        'id'      => 'street_address',
        'type'    => 'text',
        'name'    => 'Street Address',
        'binding' => 'street_number + " " + route',
    ),
Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.