Somedays ago , i was having this problem of not knowing how to get data from php with ajx and json, which i solved on myself, here is the link of my complete code
How to get Coordinates from database on server, on checkbox checked and show on googlemaps?
this is the client side code which gets coordinates through ajax request and add a marker on google maps when checkbox is checked, and removes it when un_checked.
code
function get_coordinates(checkbox){
var v_id=checkbox.id;
if(checkbox.checked){
var hr = new XMLHttpRequest();
hr.open("POST", "fetch_coordinates.php", true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var data = JSON.parse(hr.responseText);
var lat=data.loc.lat;
var lon=data.loc.lon;
addmarker(lat,lon,v_id);
}
}
hr.send("id="+v_id);
} else{
var mark = markers[v_id]; // find the marker by given id
mark.setMap(null);
delete markers[v_id];
}
}
function addmarker(lat,lon,v_id){
var marker = new google.maps.Marker({
id: v_id,
position: new google.maps.LatLng(lat, lon),
zoom: 8, //not working
map: map,
title: 'Vehicle No: '+v_id
});
markers[v_id] = marker;
}
Now when i add a marker, i set my zoom level to 8, but the map doesnot zoom, i dont know why but it stands still, just adds a marker , but is not zooming. whay is that?