Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 528799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:01:28+00:00 2026-05-13T09:01:28+00:00

The follow tells me that GMap2 is not defined. But the code that uses

  • 0

The follow tells me that GMap2 is not defined. But the code that uses GMap2 is in the callback.

        $(function() {
        $('#sample').click(function() {
            $.getScript("http://maps.google.com/maps?file=api&v=2&sensor=true&key=API_KEY_HERE", function() {
                var map = new GMap2(document.getElementById("mapTest"));
                map.setCenter(new GLatLng(18, -77.4), 13);
                map.setUIToDefault();

            });
        });
    });

<a id="sample">Click Me</a>
<div id="mapTest" style="width: 200px; height: 100px;"></div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:01:28+00:00Added an answer on May 13, 2026 at 9:01 am

    You can go two ways with this:

    1. Continue to use $.getScript:

    It seems that you need both an async=2 parameter as well as a different callback structure for it to work. My answer is adapted to your code from this great walkthrough here.

    <script type="text/javascript">
        function map_callback(){
            var map = new GMap2(document.getElementById("mapTest"));
            map.setCenter(new GLatLng(18, -77.4), 13);
            map.setUIToDefault();
        }
    
        $(function(){
           $('#sample').click(function(){
              $.getScript("http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;callback=map_callback&amp;async=2&amp;key=API_KEY_HERE");
           }
        }
    </script>
    

    2. Use the Google AJAX Loader

    Since you are already using a Google Library, why not use their loader to help you out:

    <script type="text/javascript" src="http://www.google.com/jsapi?key=ABCDEFG"></script>
    <script type="text/javascript">
       google.load("jquery", "1.3.2");
    
       google.setOnLoadCallback(function(){
           $('#sample').click(function(){
              google.load("maps", "2", {"callback" : function(){
                var map = new GMap2(document.getElementById("mapTest"));
                map.setCenter(new GLatLng(18, -77.4), 13);
                map.setUIToDefault();
              } });
           });
       }, true); // Passing true, though undocumented, is supposed to work like jQuery DOM ready
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a series of classes that tells the debug stream ( std::cout in
There is this famous quote that says Procedural code gets information then makes decisions.
I've discussed lately with one fellow a example of code where person uses nesting
This question is a follow up to a previous question I had I'm trying
let's say that I have some inputs with ID like that: ctl139_ctl00_txtValue ctl140_ctl00_txtValue ctl141_ctl00_txtValue
I've currently got a spreadsheet type program that keeps its data in an ArrayList
Trying to avoid Tell-don't-ask, I want to combine a bool property that I was
In my iPhone app, I have a UIViewController with two subviews: a main UIView
I'm trying to use System.Diagnostics to do some very basic logging. I figure I'd
I have to list folders and sub-folders from a given directory in DOS and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.