Jump to content

GMAP help with php


friedice

Recommended Posts

hello im having some trouble with my gmap

 

its just that all my markers are showing all the data from the last child of the xml file

ill explain my code here for beta explanation

 

first after the form as been submitted, it gets all the posted data from the form, then searches the database and returns all it matches and returns it back to the user, then it writes it all to an xml and then calls the displaymap.php

$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node); 
//query for doctor name


//query to search for all doctors that match the selected value of the langspoken dropdown box
$gmapSql = "SELECT * FROM Doctor";

$gmapResult = $mdb2->query($gmapSql);
$rowsFound = ($gmapResult->numRows());	

if(PEAR::isError($mdb2))
{
	echo $mdb2->getMessage() . "<br/>\n";
	echo $mdb2->getUserinfo() . "<br/>\n";
	exit;
}

//checks if any exists and displays it or displays none has been found
if(($gmapResult->numRows()) != 0)
{
	// Report how many rows were found
	$rowsfoundmessage = "{$rowsFound} records of doctors found matching your criteria <br> Address Entered: {$address}
	<br> Radius(km): {$KMradius}";
	$template->setCurrentBlock("resultsfound");
	$template->setVariable("RESULTSFOUND",$rowsfoundmessage);
	$template->parseCurrentBlock("resultsfond");

}
else
{
	$rowsfoundmessage = 'No records of doctors match your search criteria';
	$template->setCurrentBlock("resultsfound");
	$template->setVariable("RESULTSFOUND",$rowsfoundmessage);
	$template->parseCurrentBlock("resultsfound");
}



if ($rowsFound > 0)
		 {
			 // Fetch each of the query rows
			 while ($row = $gmapResult->fetchRow()) 
			 {   
				//details it back to the user using the PEAr placeholders
				$template->setCurrentBlock("doctorinfo");
				$template->setVariable("DOCTORNAME","{$row['Title']} {$row['GivenName']} {$row['Surname']}");
				$template->setVariable("DOCTORLANG", $row['LanguageSpoken']);
				$template->setVariable("DOCTOROFFICEADD", $row['OfficeAddress']);
				$template->setVariable("DOCTOROFFICENUM", $row['OfficeNumber']);
				$template->setVariable("DOCTORSPECIAL", $row['Qualifications']);
				$template->parseCurrentBlock("doctorinfo");


				 // ADD TO XML DOCUMENT NODE
				$node = $dom->createElement("marker");  
				$newnode = $parnode->appendChild($node);   

				//created attributes for each marker containing doctors details
				$newnode->setAttribute("DoctorName","{$row['Title']} {$row['GivenName']} {$row['Surname']}");
				$newnode->setAttribute("OfficeAddress", $row['OfficeAddress']);  
				$newnode->setAttribute("OfficeNumber", $row['OfficeNumber']);  
				$newnode->setAttribute("LanguageSpoken", $row['LanguageSpoken']);  
				$newnode->setAttribute("Specialty", $row['LanguageSpoken']); 


			} // end while loop body
		 } // end if $rowsFound body

		//save as an xml and overwrite existing one with this data
		echo $dom->saveXML();
		$dom->save("markers.xml");

//call this script to display the google map
echo "<script type=\"text/javascript\" src=\"displaymap.php?address=".$address."&KMradius=".$KMradius."\"></script>"; 

 

opens the displaymap.php and starts the map, makes a marker of ur location and draws a radius

it then opens the xml file, searches each child and makes a marker for it and put it on the map

my PROBLEM is the infowindow for each marker on the map  only shows details for the last child on the xml,

at ffirst i was pretty sure it would work fine since its all in for loop so that each marker it makes it shows coresponding details.

Could it be that everytime it goes in the for loop it overrides the marker2 variable with the new details?

is there a solution to this??

//Get the data from the url and store it in a javascript variable
	var address = "<?php echo $_GET['address'];?>";
	var KMradius = "<?php echo $_GET['KMradius'];?>";


	//call the functions with those parameters
	showAddress(address,KMradius);return false;

function showAddress(address,KMradius) 
{
	//converts KM radius into Miles 
	MIRadius = KMradius * 0.62137119;

	if (geocoder) 
	{
		geocoder.getLatLng(address,function(point) 
		{	
			//checks the address entered is a valid geocode address
			if (!point) 
			{
				alert("Address: "+address + " not found");
			} 
			else 
			{
				//if it is set the center of the map of that address 
				map.setCenter(point, 10);
				var marker = new GMarker(point, {draggable: true});
				GEvent.addListener(marker, "click", function() {
							marker.openInfoWindowHtml("<p>Address: <b>" + address + "</b><p>Your Are here! </p>");
							}); 
				//sets the latitude and longtude of the address into variables
				var lati=point.lat();
				var long=point.lng();
				//add the marker of the address onto the map
				map.addOverlay(marker);
				marker.openInfoWindowHtml("<p>Address: <b>" + address + "</b><p>Your Are here! </p>");


				//calls the functions with the latitude,longtude and radius and also the thickness and color of the circle
				drawCircle(lati,long,MIRadius, "#000080",1, .5, "#0000FF", .5);

			}
		}
		);
	}

	//opens the xml with all the markers and parses the data
	GDownloadUrl("markers.xml", function(data) 
	{
		var xml = GXml.parse(data);
		//goes into the root element of the xml
		var markers = xml.documentElement.getElementsByTagName("marker");
		//for each marker element in the xml, create a new marker from the address attribute
			for (var i = 0; i < markers.length; i++) 
			{	
				//gets the values of each attribute for each marker element
				var GivenName = markers[i].getAttribute("DoctorName");
				var OfficeNumber = markers[i].getAttribute("OfficeNumber");
				var LanguageSpoken = markers[i].getAttribute("LanguageSpoken");
				var addresss = markers[i].getAttribute("OfficeAddress");
				var special = markers[i].getAttribute("Specialty");
					//alert(GivenName);
					//alert(OfficeNumber);
					//alert(LanguageSpoken);
					//alert(addresss);	
					//alert(special);

				if (geocoder) 
				{

						geocoder.getLatLng(addresss,function(point) 
						{
							if (!point) 
							{	
								//if the address in the xml in not a valid geocode address, alert the user
								alert("Address: "+addresss+ " not found");
							} 
							else 
							{

							//make a variable each for latitude and longatude for the point
							var lati2 = point.lat();	
							var long2 = point.lng();

							//make a point containing the latitude and longatude
							var point = new GLatLng(lati2,long2);
							//created a marker for that point
							var marker2 = new GMarker(point,{draggable: false});
							GEvent.addListener(marker2, "click", function() {
							marker2.openInfoWindowHtml("Office Address:" + addresss + "<br/>Language Spoken: "+ LanguageSpoken + "<br/>Doctor Name:" + GivenName+ "<br/>Office Number: "+ OfficeNumber+ ".");
							});

							//var marker2 = createMarker(point,);
							//add the marker of the address in the xml onto the map
							map.addOverlay(marker2);


							}
						}
						);
				}





			}
	});
    }

 

 

thx :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.