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

  • Home
  • SEARCH
  • 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 8134521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:03:52+00:00 2026-06-06T10:03:52+00:00

I was quite familiar with the V2 api, but it’s been a while since

  • 0

I was quite familiar with the V2 api, but it’s been a while since I delved into any javascript.

I’m using an XML example found here: http://gmaps-samples-v3.googlecode.com/svn/trunk/xmlparsing/ to load markers I generate with PHP onto a map. The file is jqueryget.html and so far so good.

The problem arises when I want to refresh the markers.

The section of code is here:

google.load("maps", "3",  {other_params:"sensor=false"});
google.load("jquery", "1.3.2");

function initialize() {
var myLatlng = new google.maps.LatLng(37.4419, -122.1419);
var myOptions = {
  zoom: 13,
  center: myLatlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

jQuery.get("data.xml", {}, function(data) {
  jQuery(data).find("marker").each(function() {
    var marker = jQuery(this);
    var latlng = new google.maps.LatLng(parseFloat(marker.attr("lat")),
                                parseFloat(marker.attr("lng")));
    var marker = new google.maps.Marker({position: latlng, map: map});
 });
});
}

google.setOnLoadCallback(initialize);

I want to isolate the section that loads the markers from the initialize function, into a function I can call on click, however I can’t seem to work out how to do it.

Any advice greatly appreciated

  • 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-06-06T10:03:55+00:00Added an answer on June 6, 2026 at 10:03 am

    Set the map variable as a global variable. Move the jQuery get method call to a separate function:

    var map;
    
    function initialize() {
      ...
    
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    }
    
    //Call this function from the click event
    function createMarkers() {
    
      jQuery.get("data.xml", {}, function(data) {
        jQuery(data).find("marker").each(function() {
          var marker = jQuery(this);
          var latlng = new google.maps.LatLng(parseFloat(marker.attr("lat")),
                                    parseFloat(marker.attr("lng")));
          var marker = new google.maps.Marker({position: latlng, map: map});
       });
      });
    
    }
    
    google.setOnLoadCallback(initialize);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite familiar with PHP dockblocks since it's been my job for the last
I am very new to HTAs, but quite familiar with websites, javascript, ASP etc.
I'm quite new to Android programming but familiar with C/C++ and Linux enough to
I'm trying to pull some data into my CakePHP site using a REST API.
I'm quite familiar with the System.Diagnostics.Process class. But, I'm wondering about how I can
I am quite familiar with cocos2D (been working with it for over 1 year)
Really basic (and probably quite idiotic) question but I'm not familiar with this procedure
I have been using Visual Studio (VC++) and Windows API for a long time,
I have gotten quite familiar with django's email sending abilities, but I havn't seen
(note: I'm quite familiar with Java, but not with Hibernate or JPA - yet

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.