mercredi 11 février 2015

Fusion Tables vs. Postgres with PHP


I'm trying to draw 5 sets ~30k markers to a Google map at a time, which set is drawn depends on user input/selection.


I've noticed very slow load times by the application in rendering the points using the following code.



function set_markers(minyear,maxyear,minprice,maxprice){

if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
// this method is used to capture the response of the http request
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var pinpoints = JSON.parse(xmlhttp.responseText);
var marker;
var i=0;
var lat;
var lng;
var price;
var address;
var post_latlng;
var content;
for (i = 0;i<pinpoints.length;i++){
a=pinpoints[i];
lat=parseFloat(a["lat"]);
lng=parseFloat(a["lng"]);
price=parseFloat(a["price"]);
address=String(a["address_string"]);
date=String(a["date_of_sale"]);
post_latlng = new google.maps.LatLng(lat,lng);
content ="<b>Address:</b> " + address + "</br>" + "<b>Price:</b>€ " + price + '</br>' + "<b>Date of Sale:</b> " + date;
add_marker(address,post_latlng);
add_InfoWindow(content,marker);
}
}
}
xmlhttp.open("GET","ajax/pinpoints.php?lat1="+lat1+"&lat2="+lat2+"&lng1="+lng1+"&lng2="+lng2+"&minyear="+minyear+"&maxyear="+maxyear+"&minprice="+minprice+"&maxprice="+maxprice,true);
xmlhttp.send();
}

function add_marker(add,posit){
var marker = new google.maps.Marker({
map: map,
title: add,
position: posit
});
}
function add_InfoWindow(con,mark){
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker,'click', (function(mark,con,infowindow{
return function(){
infowindow.setContent(con);
infowindow.open(map,mark);
};
})(marker,content,infowindow));
}


I am wondering if using Fusion Tables would speed up this process and still allow me to draw the points as specified in the Javascript code above? If so, how can I call a Fusion Table from my Javascript and store the return in a JSON array so as I can cause minimal disruption to the application when switching from PHP/Postgres to Fusion Tables. I've already created the relevant Fusion Table, I just need to know if and how to connect it?


Suggestions on how to optimise the above code to speed up running time are also welcome.





Aucun commentaire:

Enregistrer un commentaire