简体   繁体   中英

Wordpress and Google Geocoder

This was working earlier and all of a sudden it just stopped. I'm enqueueing the script with this code:

wp_enqueue_script( 'google_maps', 'https://maps.googleapis.com/maps/api/js#asyncload&sensor=false&callback=initMap&key=[my api key here]', array());

When this loads however, I keep getting this in console:

Google Maps JavaScript API warning: NoApiKeys

I've tried with 2 different Google accounts and the API Key is good. I can't seem to get around this error what is my issue?

I had accidently removed some code that replaced the '#asyncload' with the proper syntax.

So the url should look like this: https://maps.googleapis.com/maps/api/js?key=[your api key here]&callback=initMap#asyncload

Then you need this to replace the '#asyncload':

function add_async($url)
{
    if (strpos($url, '#asyncload')===false)
        return $url;
    else if (is_admin())
        return str_replace('#asyncload', '', $url);
    else
        return str_replace('#asyncload', '', $url)."' async='async"; 
}
add_filter('clean_url', 'add_async', 11, 1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM