Support

Account

Home Forums ACF PRO ACF Google Maps callback error

Solved

ACF Google Maps callback error

  • Hi all,
    I am using acf to communicate and load a google map using an API, for this I use the basic example code here because I don’t need anything special apart from the API key, it has been working stably for a long time, but yesterday two different pages using the same method I get the following error:

    Loading the Google Maps JavaScript API without a callback is not supported: https://developers.google.com/maps/documentation/javascript/url-params#required_parameters js:208:292
        gea https://maps.googleapis.com/maps/api/js?key=AIzaSyA5QmFoSbWjkGOMKT-RmO_TZLh3qfnRnoY&ver=3:208
        Load https://maps.googleapis.com/maps/api/js?key=AIzaSyA5QmFoSbWjkGOMKT-RmO_TZLh3qfnRnoY&ver=3:14
        <anonymous> https://maps.googleapis.com/maps/api/js?key=AIzaSyA5QmFoSbWjkGOMKT-RmO_TZLh3qfnRnoY&ver=3:330
        <anonymous> https://maps.googleapis.com/maps/api/js?key=AIzaSyA5QmFoSbWjkGOMKT-RmO_TZLh3qfnRnoY&ver=3:330

    I have been checking the code with patience, but I can’t find the bug, if anyone has any idea I would be very grateful.

  • Same issue here. Did you find a solution @saggi?

  • @sgauder I have not received any news on this problem, in some places it is indicated to call the API url using a callback in the url (&callback=initMap) and then load the library with the code, but this does not work for me.

  • Thanks @saggi. That callback reference isn’t working for me either.

    Oddly, I’ve used the ACF map on other sites without that callback reference and they’re working fine. Not sure what’s different.

  • I came across the same issue just now. Turns out that in wp-content\plugins\advanced-custom-fields-pro\includes\fields\class-acf-field-google-map.php the callback param is set to an empty string:

    
    			// vars
    			$api = array(
    				'key'       => acf_get_setting( 'google_api_key' ),
    				'client'    => acf_get_setting( 'google_api_client' ),
    				'libraries' => 'places',
    				'ver'       => 3,
    				'callback'  => '',
    				'language'  => acf_get_locale(),
    			);
    

    Just below this there’s a filter we can use to override these params:

    
    			// filter
    			$api = apply_filters( 'acf/fields/google_map/api', $api );
    

    I found a post on Stack Overflow that suggests setting the callback param to Function.prototype, see https://stackoverflow.com/a/75212692

    This fix works for me:

    
    add_filter('acf/fields/google_map/api', function ($api) {
        $api['callback'] = 'Function.prototype';
        return $api;
    });
    
  • Thanks @youdaman. That got rid of of the callback error.

    Now, I’m seeing an error from the acfmap.js (from this example https://www.advancedcustomfields.com/resources/google-map/):

    Uncaught ReferenceError: google is not defined.

    Seems to be preventing the map from rendering on the page.

  • I was having the same issue, but @youdaman ‘s solution ended up working for me. Here is what I ended up placing within functions.php:

    
    // Advanced Custom Fields, Google Map Setup
    function my_acf_google_map_api( $api ){
        $api['key'] = 'API KEY GOES HERE';
        $api['callback'] = 'Function.prototype';
        return $api;
    }
    add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');
    

    I’m sure that can be simplified, but I was happy to get something to work!

  • @youdaman I’ve been corresponding with support on this issue. Switching the order that I was enqueuing the scripts cleared the error on the public site (i.e. enqueuing <script src=”https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY”></script&gt; before acfmap.js)

    I’ve also added the callback to the filter.

    My new issue is now a Google API error using the map field in the WP admin. Support is still assisting with that but no resolution yet. Because of that error, it seems to be preventing me from setting and then pulling the lat/lng data from the fields.

    I’ll update this post when that’s resolved.

  • @sgauder, no worries. Just offering a solution as I came across it. Good luck!

  • para mi ninguna de estas formas funcionan correctamente. Yo cargo todos los scripts desde functions.php

      wp_register_script('google_js',
                'https://maps.googleapis.com/maps/api/js?key=API_KEY', true, '3');
                wp_enqueue_script('google_js');
                
                wp_register_script('custom-maps', THEME_DIR . '/js/google-maps.js', array('jquery'), true, '1');
                wp_enqueue_script('custom-maps');

    and I have implemented the callback function as well.

    function my_acf_google_map_api( $api ){
        $api['key'] = 'API_KEY';
        $api['callback'] = 'Function.prototype';
        return $api;
    }
    add_filter('acf/fields/google_map/api', 'my_acf_google_map_api');

    But I still have the same error

  • This continues to be an issue for me. I’ve added the line “$api[‘callback’] = ‘Function.prototype’;” to my function.

    For some reason though, the callback is not getting appended to the script reference when it’s published to the site, just the API key like so:

    <script async src=”https://maps.googleapis.com/maps/api/js?key=API_KEY”></script&gt;

    That’s the part that is a mystery. It sounds like it’s working for some of you but not all of us.

    <sigh>

  • I’m not sure how, but it has solved itself, maybe it was a bug in ACF or a bug from google that have been solved by the API, but no longer emits any kind of failure, so I give this issue solved

    Thank you all!

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.