I am trying to plot addresses from my db via xml format. I have got a PHP file that plot these addresses in xml format, and I would like to display them into google map as markers.
generatexml.php working fine, it display all addresses as xml format but I can't figure out how to plot these addresses into map as marker.
Result of generatexml.php
<markers>
<marker address="Lichfield Road, Burton on Trent, United Kingdom"/>
<marker address="Anchor BuildingsWestgate, Morecambe, United Kingdom"/>
</markers>
Here's my php file that generate xml file.
// file name generatexml.php
require ('connection.php');
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
// Opens a connection to a MySQL server
$connection=mysqli_connect($host, $username, $password);
if (!$connection) { die('Not connected : ' . mysqli_error());}
// Set the active MySQL database
$db_selected = mysqli_select_db($connection ,$database );
if (!$db_selected) {
die("Database selection failed: " . mysqli_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM mapping WHERE 1";
$result = mysqli_query($connection , $query);
if (!$result) {
die('Invalid query: ' . mysqli_error());
}
header('Content-type: text/xml');
// Iterate through the rows, adding XML nodes for each
while ($row = @mysqli_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("address", $row['address']);
}
echo $dom->saveXML();
?>
<script>
src="https://maps.googleapis.com/maps/api/jskey=mykey&sensor=false">
</script>
function initialise() {
myLatlng = new google.maps.LatLng(54.559323,-3.321304);
mapOptions = {
zoom: 5,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
}
geocoder = new google.maps.Geocoder();
infoWindow = new google.maps.InfoWindow;
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
xmlUrl = "inc/generatexml.php";
loadMarkers();
}
google.maps.event.addDomListener(window, 'load', initialise);
Any idea or examples ?