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 8001375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:04:41+00:00 2026-06-04T16:04:41+00:00

I have a function that creates Google maps markers. I pass in data from

  • 0

I have a function that creates Google maps markers. I pass in data from a database query. Then I have the function perform another database query using one value as the foreign key. I am trying then to put all the results (the data from the first query and the data from the second query) into a string, which the marker will display in an infoWindow.

But somehow, the program views the string as “undefined” unless I build it outside of the $.post function for the second query. What’s going on? Shouldn’t the program be able to read that string?

Here is my code:

function createMarker(marker_id, point,street, neighborhood, date,map) {
            // Create the HTML text based on the values passed in from XML
            $.post('get_victimdata.php', {marker_id:marker_id},
                 function(victimdata){

                     objVictimdata = jQuery.parseJSON(victimdata);
                     markerhtml = "";
                      markerhtml += "<strong>Street: </strong>" + street + "<br>";
                      markerhtml += "<strong>Neighborhood: </strong>" + neighborhood + "<br>";
                      markerhtml += "<strong>Date: </strong>" + date + "<br><br>";
                     for (var i=0; i < objVictimdata.length; i++) {
                         var image_path = objVictimdata[i].image_path;
                         var image_height = objVictimdata[i].image_height;
                         markerhtml += "<strong>Victim Name: </strong>" + objVictimdata[i].name + "<br>";
                         markerhtml += "<strong>Age:</strong> " + objVictimdata[i].age + "<br>";
                         markerhtml += "<strong>Race:</strong> " + objVictimdata[i].race + "<br>";
                         markerhtml += "<strong>Gender:</strong> " + objVictimdata[i].gender + "<br>";
                         markerhtml += "<strong>Cause:</strong> " + objVictimdata[i].cause + "<br><br>";
                         console.log(markerhtml);

                     }//end for

            })//end post
            console.log(markerhtml);


            var image = new google.maps.MarkerImage('http://labs.google.com/ridefinder/images/mm_20_green.png',
            new google.maps.Size(12, 20),
            new google.maps.Point(0,0),
            new google.maps.Point(6, 20));

            var marker = new google.maps.Marker({
              position: point,
              map: map,
              icon: image
            });

            var infoWindow = new google.maps.InfoWindow(); //initialize infoWindow
              // Add a click event to each marker which will open the HTML window
            marker.infowindow = new google.maps.InfoWindow({
              content: markerhtml
            });


            google.maps.event.addListener(marker, "click", function() {
                marker.infowindow.open(map, marker);
            });

};//end create marker
  • 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-04T16:04:43+00:00Added an answer on June 4, 2026 at 4:04 pm

    Try the following code. The diffence is that I placed all statemetns following the call to $.post inside of the anonymous function which is fired after and only if the post succeeds. When you call $.Post, the function on the inside isn’t ran until the post is complete, but execution still continues to the following statements while the post occurs in the background!

    Paraphrased The inner anonymous function has been expanded to include most of the code. If you are unsure of the difference, try using a program like WinMerge which will show you the difference: winmerge showing the difference

    function createMarker(marker_id, point,street, neighborhood, date,map) {
                // Create the HTML text based on the values passed in from XML
                $.post('get_victimdata.php', {marker_id:marker_id},
                     function(victimdata){
    
                         objVictimdata = jQuery.parseJSON(victimdata);
                         markerhtml = "";
                          markerhtml += "<strong>Street: </strong>" + street + "<br>";
                          markerhtml += "<strong>Neighborhood: </strong>" + neighborhood + "<br>";
                          markerhtml += "<strong>Date: </strong>" + date + "<br><br>";
                         for (var i=0; i < objVictimdata.length; i++) {
                             var image_path = objVictimdata[i].image_path;
                             var image_height = objVictimdata[i].image_height;
                             markerhtml += "<strong>Victim Name: </strong>" + objVictimdata[i].name + "<br>";
                             markerhtml += "<strong>Age:</strong> " + objVictimdata[i].age + "<br>";
                             markerhtml += "<strong>Race:</strong> " + objVictimdata[i].race + "<br>";
                             markerhtml += "<strong>Gender:</strong> " + objVictimdata[i].gender + "<br>";
                             markerhtml += "<strong>Cause:</strong> " + objVictimdata[i].cause + "<br><br>";
                             console.log(markerhtml);
    
                         }//end for
                        console.log(markerhtml);
    
    
                        var image = new google.maps.MarkerImage('http://labs.google.com/ridefinder/images/mm_20_green.png',
                        new google.maps.Size(12, 20),
                        new google.maps.Point(0,0),
                        new google.maps.Point(6, 20));
    
                        var marker = new google.maps.Marker({
                          position: point,
                          map: map,
                          icon: image
                        });
    
                        var infoWindow = new google.maps.InfoWindow(); //initialize infoWindow
                          // Add a click event to each marker which will open the HTML window
                        marker.infowindow = new google.maps.InfoWindow({
                          content: markerhtml
                        });
    
    
                        google.maps.event.addListener(marker, "click", function() {
                            marker.infowindow.open(map, marker);
                        });
    
    
                })//end post
    
    };//end create marker
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script that creates a div, adds a Google Maps DOM
I have a function that creates zip files when passed an array of files
I have a function that creates a course. I am trying to get the
I have a function that creates a 2D vector void generate(int n) { vector<
Lets say I have a recursive function that creates lists within lists. It return
Say I have a function func(i) that creates an object for an integer i,
I have this function in a Code Igniter model that creates a new video.
I have the following function that takes a number like 5 and creates a
I have a win form that creates a site in IIS7. One function needs
i have DataBase function that calculate distance by coordinates CREATE OR REPLACE FUNCTION distance(lat1

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.