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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:34:24+00:00 2026-06-12T17:34:24+00:00

So I’m trying to combine two Google Maps API tutorials into one map. This

  • 0

So I’m trying to combine two Google Maps API tutorials into one map. This documentation and this one.

I use to have two maps for each displayed on the sample page and now I want to have one. Everything works except for when I try to save the content to the database. document.getElementbyId doesn’t return anything from the form in the info window just the coordinates.

It works when the maps are separate but not when they are together.

This is the code that I combined:

var customIcons = {
  blue: {
    icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
    shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
  },
  red: {
    icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
    shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
  }
};

var locationInfowindow;
var locationMarker;

function initialize() {
//get the html from the water
    var waterHTML = "Why is water important in your community?" +
            "<table>" +
             "<tr><td>Name:</td> <td><input type='text' id='watername'/> </td> </tr>" +
             "<tr><td>School:</td> <td><input type='text' id='wateraddress'/></td> </tr>" +
             "<tr><td>Reason:</td> <td><input type='text' id='waterreason'/> </td></tr>" +
             "<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr>";


//setup Map 
  var map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(37.926868, -104.501953),
    zoom: 5,
    mapTypeId: 'roadmap'
  });

  //start the markers from the database
  var infoWindow = new google.maps.InfoWindow;

  // Change this depending on the name of your PHP file
  downloadXMLUrl('mapxml.php', function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
      var name = markers[i].getAttribute("name");
      var address = markers[i].getAttribute("school");
      var math = markers[i].getAttribute("reason");
      var point = new google.maps.LatLng(
          parseFloat(markers[i].getAttribute("lat")),
          parseFloat(markers[i].getAttribute("lng")));
      var html = "<b>" + name + "</b> <br/> <i>" + address + "</i><br/>" +math ;
      var icon = customIcons['blue'] || {};
      var marker = new google.maps.Marker({
        map: map,
        position: point,
        icon: icon.icon,
        shadow: icon.shadow
      });
      bindInfoWindow(marker, map, infoWindow, html);
    }
  });

        //Try HTML5 geolocation
  if(navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        var pos = new google.maps.LatLng(position.coords.latitude,
                                         position.coords.longitude);

     locationInfowindow = new google.maps.InfoWindow({
        content: waterHTML
     });

     locationMarker = new google.maps.Marker({
        draggable: true,
        position: pos,
        map: map,
        title: 'Water Event'
    });

    locationInfowindow.open(map,locationMarker);
            map.setCenter(pos);
      }, function() {
        handleNoGeolocation(true);
      });

    } else {
      // Browser doesn't support Geolocation
      handleNoGeolocation(false);
    }

}

function bindInfoWindow(marker, map, infoWindow, html) {
  google.maps.event.addListener(marker, 'click', function() {
    infoWindow.setContent(html);
    infoWindow.open(map, marker);
  });
}


function downloadXMLUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}



 function handleNoGeolocation(errorFlag) {
    if (errorFlag) {
      var content = 'Your browser doesn\'t support geolocation.' + '</br>'+
            "Why is water important in your community?” " +
            "<table>" +
             "<tr><td>Name:</td> <td><input type='text' id='watername'/> </td> </tr>" +
             "<tr><td>School:</td> <td><input type='text' id='wateraddress'/></td> </tr>" +
             "<tr><td>Reason:</td> <td><input type='text' id='waterreason'/> </td></tr>" +
             "<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr>";
    } else {
      var content = 'Error: Your browser doesn\'t support geolocation.' + '</br>' + html;
    }

    var options = {
      map: map,
      position: new google.maps.LatLng(37.926868, -104.501953),
      content: content
    };

    locationInfowindow = new google.maps.InfoWindow(options);
    map.setCenter(options.position);
  }

  google.maps.event.addDomListener(window, 'load', initialize);

function saveData() {

  var watername = escape(document.getElementById("watername").value);

  console.log(watername);
  var wateraddress = escape(document.getElementById("wateraddress").value);

  console.log(wateraddress);
  var waterreason = document.getElementById("waterreason").value;
  console.log(waterreason);

  var latlng = locationMarker.getPosition();

  var url = "phpsqlinfo_addrow.php?name=" + watername + "&school=" + wateraddress + "&reason=" + waterreason + "&lat=" + latlng.lat() + "&lng=" + latlng.lng();

  console.log(url);

  downloadUrl(url, function(data, responseCode) {

  console.log("inurl");
   // if (responseCode == 200 && data.length <= 1) {
      locationInfowindow.close();
      document.getElementById("message").innerHTML = "Location added. Refresh to see your addition!";
   // }
  });
}


function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request.responseText, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}




function doNothing() {}
  • 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-12T17:34:25+00:00Added an answer on June 12, 2026 at 5:34 pm

    I can’t tell you exactly why this happens, but there is some garbage inside the document, a hidden node-copy of the waterHTML.

    getElementById() retrieves the first element with a given ID in a document, so you always get the value of this copy instead of desired value. This copy will be removed somehow after the first button-click.

    Suggestion: Instead of IDs use name-attributes, you will be able to retrieve the last item from the returned nodeList:

      var waternames = document.getElementsByName("watername");
      var watername = escape(waternames[waternames.length-1].value);
      //the same for waterreason and wateraddress
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

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.