Here is the source code for the book: googlemapsbook.com/gmaps_php_code.tar.gz
I just run the source code of CHP 2 & 3 as they are ... copied then pasted.

I started to run CHP 2 's source code. It works fine, but an XML Error appears.
(The same error appear when i run CHP 3 's source code)

I need someone familiar with Google Maps Applications.
Ofcourse if you dont have a Google Maps API Key ... please obtain one from google .. its free.
Change the API Key in the source code file.

    Uh, did you happen to take a look at the homepage of the site you linked to?

    Not only do they warn you that their book is "severely out of date", they even go on to reference someone else's book and to "NOT BUY [THEIRS]." All of this deprecation happened close to 3 years ago, so it's probably even more out of date...

    (Not to mention that after a quick peek at the source code, it doesn't look extremely well written in the first place - even for something released 5+ years ago.)

      The Sample code is fine written ... i need to know why this XML error keeps appearing.
      Try to copy and paste it .. you shall see the error.

      I need this solution very deeply

        AliEzz;11019723 wrote:

        The Sample code is fine written ... i need to know why this XML error keeps appearing.

        I would submit that code which produces an error is not "fine." Further, I suspect you would agree, or you wouldn't be asking for help in the first place.

        AliEzz;11019723 wrote:

        Try to copy and paste it .. you shall see the error.
        I need this solution very deeply

        Why don't you tell us what the error is?

          These are the 4 files involved:

          map_functions.js

          var centerLatitude = 37.4419;
          var centerLongitude = -122.1419;
          var startZoom = 12;

          var map;

          function init() {
          map = new GMap2(document.getElementById("map"));
          map.addControl(new GSmallMapControl());
          map.addControl(new GMapTypeControl());
          map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);

          //Note: this call to retrieve markers is required for Listing 3-8
          retrieveMarkers();

          / [listing 3-4] /
          GEvent.addListener(map, "click", function(overlay, latlng) {
          //only perform the click if the window is closed and the click was directly on the map.
          if(!overlay) {
          //create an HTML DOM form element
          var inputForm = document.createElement("form");
          inputForm.setAttribute("action","");
          inputForm.onsubmit = function() {storeMarker(); return false;};

          		//retrieve the longitude and lattitude of the click point
          		var lng = latlng.lng();
          		var lat = latlng.lat();
          
          		inputForm.innerHTML = '<fieldset style="width:150px;">'
          		+ '<legend>New Marker</legend>'
          		+ '<label for="found">Found</label>'
          		+ '<input type="text" id="found" style="width:100%;"/>'
          		+ '<label for="left">Left</label>'
          		+ '<input type="text" id="left" style="width:100%;"/>'
          		+ '<input type="submit" value="Save"/>'
          		+ '<input type="hidden" id="longitude" value="' + lng + '"/>'
          		+ '<input type="hidden" id="latitude" value="' + lat + '"/>'
          		+ '</fieldset>';
          
          		map.openInfoWindow (latlng,inputForm);
          	}
          });

          / [listing 3-4 end] /

          }

          window.onload = init;

          / [listing 3-5] /
          function storeMarker(){
          var lng = document.getElementById("longitude").value;
          var lat = document.getElementById("latitude").value;

          var getVars =  "?found=" + document.getElementById("found").value + "&left=" + document.getElementById("left").value + "&lng=" + lng + "&lat=" + lat ;
          
          var request = GXmlHttp.create();
          
          //open the request to storeMakres.php on your server
          request.open('GET', 'storeMarker.php' + getVars, true);
          request.onreadystatechange = function() {
          	if (request.readyState == 4) {
          		//the request in complete
          
          		var xmlDoc = request.responseXML;
          
          		//retrieve the root document element (response)
          		var responseNode = xmlDoc.documentElement;
          
          		//retrieve the type attribute of the node
          		var type = responseNode.getAttribute("type");
          
          		//retrieve the content of the responseNode
          		var content = responseNode.firstChild.nodeValue;
          
          		//check to see if it was an error or success
          		if(type!='success') {
          			alert(content);
          		} else {
          			//Create a new marker and add it's info window.
          			var latlng = new GLatLng(parseFloat(lat),parseFloat(lng));
          
          			var marker = createMarker(latlng, content);
          
          			map.addOverlay(marker);
          			map.closeInfoWindow();
          		}
          	}
          }
          request.send(null);
          return false;

          }

          function createMarker(latlng, html) {
          var marker = new GMarker(latlng);
          GEvent.addListener(marker, 'click', function() {
          var markerHTML = html;
          marker.openInfoWindowHtml(markerHTML);
          });
          return marker;
          }
          / [listing 3-5 end] /

          / [listing 3-8] /
          function retrieveMarkers() {
          var request = GXmlHttp.create();

          //tell the request where to retrieve data from.
          request.open('GET', 'retrieveMarkers.php', true);
          
          //tell the request what to do when the state changes.
          request.onreadystatechange = function() {
          	if (request.readyState == 4) {
          		var xmlDoc = request.responseXML;
          
          		var markers = xmlDoc.documentElement.getElementsByTagName("marker");
          		for (var i = 0; i < markers.length; i++) {
          			var lng = markers[i].getAttribute("lng");
          			var lat = markers[i].getAttribute("lat");
          			//check for lng and lat so MSIE does not error
          			//on parseFloat of a null value
          			if(lng && lat) {
          				var latlng = new GLatLng(parseFloat(lat),parseFloat(lng));
          
          				var html = '<div><b>Found</b> '
          				+ markers[i].getAttribute("found")
          				+ '</div><div><b>Left</b> '
          				+ markers[i].getAttribute("left")
          				+ '</div>';
          
          				var marker = createMarker(latlng, html);
          				map.addOverlay(marker);
          			}
          		} //for
          	} //if
          } //function
          
          request.send(null);

          }
          / [listing 3-8 end] /

          index.php

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <title>Final Map</title>
          <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=type_in_your_key" type="text/javascript"></script>
          <script src="map_data.php" type="text/javascript"></script>
          <script src="map_functions.js" type="text/javascript"></script>
          <link href="style.css" rel="stylesheet" type="text/css" />
          <!--[if IE]><style type="text/css">v:*{behavior:url(#default#VML);}</style><![endif]-->
          </head>
          <body>
          <div id="map"></div>
          </body>
          </html>

          storeMarker.php

          <?php
          header('Content-Type: text/xml;charset=UTF-8');

          //see Listing 3-9 for icon related items in the code

          $lat = (float)$GET['lat'];
          $lng = (float)$
          GET['lng'];
          $found = htmlspecialchars(strip_tags(utf8_encode($GET['found'])));
          $left = htmlspecialchars(strip_tags(utf8_encode($
          GET['left'])));
          $icon = htmlspecialchars(strip_tags(utf8_encode($_GET['icon'])));

          //Create an XML node
          $marker = <<<MARKER
          <marker lat="$lat" lng="$lng" found="$found" left="$left" icon="$icon"/>
          MARKER;

          //open the data.xml file for appending
          $f=@fopen('data.xml', 'a+');
          if(!$f) die('<?xml version="1.0"?>
          <response type="error"><![CDATA[Could not open data.xml file]]></response>
          ');

          //add the node
          $w=@fwrite($f, $marker);
          if(!$w) die('<?xml version="1.0"?>
          <response type="error"><![CDATA[Could not write to data.xml file]]></response>');

          @fclose($f);

          //return a response
          $newMarkerContent = "<div><b>Found</b> $found</div><div><b>Left</b> $left</div>";

          echo <<<XML
          <?xml version="1.0"?>
          <response type="success" icon="$icon"><![CDATA[$newMarkerContent]]></response>
          XML;
          ?>

          retrieveMarkers.php

          <?php
          header('Content-Type: text/xml;charset=UTF-8');
          $markers = file_get_contents('data.xml');
          echo <<<XML
          <markers>
          $markers
          </markers>
          XML;
          ?>

            That error means that there is extra content outside of the root XML element. For example, this is valid:

            <root>
               <item/>
               <other/>
               <whatever/>
            </root>

            this is not:

            <root>
               <item/>
               <other/>
            </root>
            <root2>
               <whatever/>
            </root2>

            and neither is this:

            <root>
               <item/>
               <other/>
            </root>
            <b>Warning:</b> PHP printed an error message

            I hope this helps you understand what's going on, but I'm with brad -
            [indent]don't use code that even the authors say shouldn't be used.[/indent]

              Write a Reply...