Hi,
thanks for that calculation. i am finding it extremely accurate.
I am wondering what kind of index you are using on your tables?
I have a table with over 2 million rows, so its taking longer than I would like to bring the results back.
Has anyone optimised a table for this kind of thing before?
Kev
How I originally set this is up to have a “points” table which is simply id, lat, long
Then, from there we set up a data table that has the info for the position and then uses a point_id for the GeoPoint field..
You use a indexed Double type for the lat/long and run the query against that table and then right join in the data table with the point_id’s matching.
For MySql machines, my suggestion is ReiserFS for the file system (assuming dedicated mysql machine) and make sure your my.cnf file is fully optimized for the machine.. I should write up my config stuff for determining the proper my.cnf options.For this, you want to watch your join/sort server variables to make sure things are well speedy.
MyISAM engine type is usually what I use, however for data that is queried a lot and not changed often you can use HEAP tables to increase performance a lot. HEAP tables can be flushed to disk via a cron as needed to make sure new data is saved.
Just some ideas to speed things up.
Thanks to joeldg for the original post (INCREDIBLE, man) and Claude for the clarification.
I am wondering what kind of index you are using on your tables?
I have a table with over 2 million rows, so its taking longer than I would like to bring the results back.
Has anyone optimised a table for this kind of thing before?
Typo: In “ORDER BY 3963.191 … PI()* -73.99319 /180)))”.
You have ‘*’ and ‘-’ together, it might end up with some errors when used w/ variables e.g. *-$longitude. Just put “()” around longitude value:)
]]>Could you give a brief concrete example of how to work a bounding-box subquery into your code? I’ve got a piece of mysql that looks very similar to your code above. It works but runs a bit slow, since it’s joining against over 850,000 Canadian postal codes!
I’d like to filter out everything but say a 10-kilometre box around the postal code I’m interested in, but I’m new enough to SQL that I can’t figure out how to do the subquery or subselection. I’ve looked at the mysql docs but am still confused.
TIA,
Howard
you can use this combined with this great google maps example:
http://maps.forum.nu/gm_clickable_circle.html
just change a function.. and post the query to the following action..
function drawFilledCircle(){
oStatusDiv = document.getElementById(”statusDiv”);
var zoom = map.getZoom();
var centerPt = normalProj.fromLatLngToPixel(centerMarker.getPoint(), zoom);
var radiusPt = normalProj.fromLatLngToPixel(radiusMarker, zoom);
var circlePoints = Array();
with (Math) {
var radius = floor(sqrt(pow((centerPt.x-radiusPt.x),2) + pow((centerPt.y-radiusPt.y),2)));
var thickness = min(255,radius);
for (var n = 1 ; n \n’;
oStatusDiv.innerHTML += ‘Circumference on Earth: ‘ + (PI*radOnEarth*2).toFixed(3) + ‘ km\n’;
oStatusDiv.innerHTML += ‘Areal on Earth: ‘ + (PI*pow(radOnEarth,2)).toFixed(3) + ‘ km\n’;
oStatusDiv.innerHTML += ”;
oStatusDiv.innerHTML += ’select city,latitude,longitude, acos(SIN( PI()* ‘+ lat +’ /180 )*SIN( PI()*latitude/180 ))+(cos(PI()* ‘+ lat +’ /180)*COS( PI()*latitude/180) *COS(PI()*longitude/180-PI()* ‘+ lng +’ /180))* 6378.137 AS distance FROM geodatas WHERE 1=1 AND 6378.137 * ACOS( (SIN(PI()* ‘+ lat +’ /180)*SIN(PI() * latitude/180)) + (COS(PI()* ‘+ lat +’ /180)*cos(PI()*latitude/180)*COS(PI() * longitude/180-PI()* ‘+ lng +’ /180))) ‘;
map.removeOverlay(circleLine2);
circleLine2 = new GPolyline(circlePoints,’#96BDFE’,thickness,0.5);
map.addOverlay(circleLine2);
}
}
}
thanks a lot.. very appreciative.
]]>