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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:02:38+00:00 2026-05-28T16:02:38+00:00

Based on a user’s selection from a drop down, the AJAX retrieves latitude and

  • 0

Based on a user’s selection from a drop down, the AJAX retrieves latitude and longitude for locations that are supposed to be marked on the map with markers, but I can’t get the markers to display. Below is the code.

function selectRoute() {
        var route = $("select option:selected").val();
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else {
            // code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                var locations = xmlhttp.responseText;
                var marker, i;
                for (i = 0; i < locations.length; i++) {
                    marker = new google.maps.Marker({
                        position: new google.maps.LatLng(locations[i][0], locations[i][1]),
                        map: map
                    });
                }
            }
        }
        marker.setMap(map);
        xmlhttp.open("GET","../lib/markers.php?route="+route,true);
        xmlhttp.send();
    }

Here is what the responseText looks like that is retrieved from the markers.php page:

[[38.018914, -121.945154], [38.003275, -122.024597], [37.973737, -122.029095], and on and on];

My only thought is that the problem is this code isn’t in the initialize() function that initializes the Google Map, but if that’s the problem I haven’t been able to combine the two functions if you will. Beyond that I’m clueless what’s not working. Thanks in advance!

  • 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-28T16:02:39+00:00Added an answer on May 28, 2026 at 4:02 pm
     var locations = xmlhttp.responseText;
    

    So location is a string, you need to parse the JSON. Then everything should work quite nicely

    … except for marker.setMap(map);, it’s outside the function; and you don’t need it anyway cause you set map in the marker options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a web-based user interface that plots some data from a database
I have a PHP script that creates other PHP files based on user input.
I am working on a view that selects an image (chart) based on user
I am implementing a user based reccomender that should work just on categories of
I'm creating files based on user data (taking from the database table, writing to
Basically I wrote a script that generates a xml file based on user input.
I'm creating a web page based on user input from a form. After the
I have a div that I want to appear based on user input (works),
I have this pseudo code to display different content based on user selection, which
I'm attempting to produced a timestamp based off user's selection. I have a form

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.