Here is the code I've been working on:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps AJAX + mySQL/PHP Example</title>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC-dbN2gdvXsx09jfJHmNc8"
type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
var customIcons = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(-6.289796, 106.822370),
zoom: 11,
mapTypeId: 'roadmap'
});
//^ HOW CAN THE CENTER VALUE IN VAR POINT BE USED IN FUNCTION LOAD()? ??? ^ //
var markarray=[]
function load() {
for (var i = 0; i < markarray.length; i++) {
markarray[i].setMap(null);
}
markarray = [];
console.log("ok")
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("http://localhost/maps6/genxml.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 date_taken = markers[i].getAttribute("date_taken");
//var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
//^ HOW TO GET THE POINT VALUE TO CENTER IN VAR MAP ???? ^ //
var html = "<b>" + name + "</b> <br/>" + date_taken;
var icon = 'mark.png';
var marker = new google.maps.Marker({
map: map,
position: point,
icon: 'mark.png',
animation: google.maps.Animation.BOUNCE,
shadow: icon.shadow
});
markarray.push(marker);
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
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, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
$("#BtnClicked").live('click',function(){load();});
setInterval(function() {load();},3000);
});
//]]>
</script>
</head>
<body>
<div id="map" style="width: 1280px; height: 720px"></div>
<a href="#" id="BtnClicked">test</a>
</body>
</html>
Upon running the code, the result can be viewed here: https://i.sstatic.net/mLhOy.png
^ The green marker automatically updates its position based on MySQL Database without having to reload the entire Google Maps page.
Therefore, I am curious about how to retrieve the Google Maps CENTER (in var map) from VAR POINT within the function load()