Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Can't get Google Maps api working in wordpress

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #145273
    CameronDuthie
    Participant

    Hi there,

    This has been giving me the run around all day. I can’t seem to get google maps api running in wordpress.

    My console outputs:

    • Uncaught ReferenceError: initialize is not defined

    I’m using the wp_register_script to load Google Maps api into my site as so.

    wp_register_script( 'maps', 'http://maps.google.com/maps/api/js?sensor=false', array(), null, false );
    wp_enqueue_script('maps');
    

    I’ve tried loading this into the footer and header of my site to see if it makes any difference but it doesn’t seem to.

    As it stands i’ve got my jQuery and Googlemaps scripts loading in my header.php

    Would anyone know how to get this working as i’m totally stumped with it?

    Link to the page in question is here, http://test.freelandfreight.co.uk/contact/

    Here’s a plain HTML version of the site where it’s working, http://madewithfabric.com/freelands/contact.html

    Thank you,

    #145429
    thechrisroberts
    Participant

    The problem is caused by how you define initialize(). If I’m reading it right, your initialize() function is in your site.js file but it’s wrapped in jQuery(document).ready(…) which if nothing else causes a scoping problem – the initialize function is not accessible outside the call to jQuery ready.

    Move initialize outside jQuery ready and see if that takes care of it. You might also enqueue your site.js the same way you enqueue the Maps API so that it loads in the header rather than the body.

    #145935
    CameronDuthie
    Participant

    @thechrisroberts Just want to apologise for not getting back to you sooner.

    You were spot on, sir! I took the initialize(). function outside the jQuery and loaded my site.js in the same place as the api and hey presto there’s my map!

    Thanks again, Chris.

    //Cam

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.