I am using PHP to get data from a MySQL database, and use the data to drop multiple markers into Google Maps. Please give me some suggestions for my code.
<?php
require_once 'Common/system_start.php';
$sql="select * from tab_mem order by sn desc ";
$result= mysql_query($sql);
$data=mysql_fetch_assoc($result);
$row=mysql_num_rows($result);
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("address", $row['address']);
}
echo $dom->saveXML();
?>
HTML5
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var map;
var geocoder;
//initial GPS
navigator.geolocation.watchPosition(onSuccess, onError, { frequency: 3000 });
function onSuccess(position){
//get GPS latlong
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// display map
var gmap = new google.maps.Map(
map_div, {
zoom:16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
//drop the marker
function drop() {
for (var i = 0; i < a; i++) {
setTimeout(function() {
addMarker();
}, i * 200);
}
}
//decode address to latlng
//pass address data from PHP
while (markers.length){
var address="";
geocoder=new google.maps.Geocoder();
alert("...");
}
geocoder.geocode({'address':address},function(results,status){
if(status==google.maps.GeocoderStatus.OK){
function addMarker() { markers.push(new google.maps.Marker({
postion:results().geometry.location,
map:gmap,
animation:google.map.animation.DROP
}));
}
// Sets the map on all markers in the array.
// function setAllMap(map) {
// for (var i = 0; i < markers.length; i++) {
// markers[i].setMap(map);
//}
// }
//markerNearBy.setMap(map);
}else{
alert("Geocode was not sucessful for the following reason:"+status);
}
});
}
}
function onError(error) {
alert('code: '+ error.code+ '\n'
+'message: ' + error.message + '\n');
}
</script>
</head>
<body onLoad="load()">
<!-- map display here-->
<div id="map_div""></div>