I will guess that "$zoekafstand" is a search radius in kilometres, and
you're attempting to convert that into degrees via a figure in miles.
So you are using an approximate km/miles conversion, and then a
conversion from miles to degrees which only works in a north-south
direction (and again, is approximate).
And you're complaining that going through two approximations doesn't
produce an exact result. (0.000001deg is under 7cm E-W at 52N, and
around 11cm N-S)
Solution: don't use that method. Use the haversine method to calculate
distance server-side, or the API's methods client-side.
"Why" is because you're using the wrong method, as I explained
earlier. If you want to convince me (and, presumably, Google) that
you're using the right method, you're going to have to provide some
worked examples with real data.
Both are version 3
In this page the lat and lng are geberated at the client side and come on the server side from $zoekaklat and $zoekaklng:
$naarposlat = $zoekaklat; // = 51.49457580000001
$naarposlng = $zoekaklng; // = 4.287162200000012
if($naarposlat==0 and $naarposlng==0) {
$zoekmessage2 = $arz_zoekmessage;
}
else {
$maxlat = $naarposlat + ( $zoekakafstand / (69 * 1.61)); // 69 miles per degree of latitude
$minlat = $naarposlat - ( $zoekakafstand / (69 * 1.61));
$maxlng = $naarposlng + ( $zoekakafstand / ( 69.172 * 1.61 * cos( $naarposlat * 0.0174533 ) ) );
$minlng = $naarposlng - ( $zoekakafstand / ( 69.172 * 1.61 * cos( $naarposlat * 0.0174533 ) ) );
$ritten = "SELECT *,(6366*acos(cos(radians(".$naarposlat."))*cos(radians(`naarpllat`))*cos(radians(`naarpllng`)-radians(".$naarposlng."))+sin(radians(".$naarposlat."))*sin(radians(`naarpllat`)))) AS verschil FROM ritten force index (naarpositie) WHERE vraag_aanbod like '$ag' AND naarpllat < $maxlat AND naarpllat > $minlat AND naarpllng < $maxlng AND naarpllng > $minlng AND vertrekdatum >= '$datum' HAVING verschil <= $zoekakafstand";
This select statement is the echo of $ritten:
SELECT *,(6366*acos(cos(radians(51.49457580000001))*cos(radians(`naarpllat`))*cos(radians(`naarpllng`)-radians(4.287162200000012))+sin(radians(51.49457580000001))*sin(radians(`naarpllat`)))) AS verschil FROM ritten force index (naarpositie) WHERE vraag_aanbod like 'A%' AND naarpllat < 51.6296014549 AND naarpllat > 51.3595501451 AND naarpllng < 4.50350079762 AND naarpllng > 4.07082360238 AND vertrekdatum >= '2011-07-12' HAVING verschil <= 15
This is from another page where the lat and lng are generated on the server side:
$url = "http://maps.googleapis.com/maps/api/geocode/xml?address=".urlencode($zoekpos2)."&sensor=false";
$geo = new SimpleXMLElement(file_get_contents($url));
usleep(1750000);
if ($geo->status == "OK") {
$naarposlat = $geo->result->geometry->location->lat; // = 51.4945758 in the calculation this is handled as 51 ???
$naarposlng = $geo->result->geometry->location->lng; // = 4.2871622 in the calculation this is handled as 4 ???
$maxlat = $naarposlat + ( $zoekafstand2 / (69 * 1.61)); // 69 miles per degree of latitude
$minlat = $naarposlat - ( $zoekafstand2 / (69 * 1.61));
$maxlng = $naarposlng + ( $zoekafstand2 / ( 69.172 * 1.61 * cos( $naarposlat * 0.0174533 ) ) );
$minlng = $naarposlng - ( $zoekafstand2 / ( 69.172 * 1.61 * cos( $naarposlat * 0.0174533 ) ) );
$ritten = "SELECT *,(6366*acos(cos(radians(".$naarposlat."))*cos(radians(`naarpllat`))*cos(radians(`naarpllng`)-radians(".$naarposlng."))+sin(radians(".$naarposlat."))*sin(radians(`naarpllat`)))) AS verschil FROM ritten force index (naarpositie) WHERE vraag_aanbod like '$ag' AND naarpllat < $maxlat AND naarpllat > $minlat AND naarpllng < $maxlng AND naarpllng > $minlng AND vertrekdatum >= '$datum' HAVING verschil <= $zoekafstand2";
This select statement is the echo of $ritten:
SELECT *,(6366*acos(cos(radians(51.4945758))*cos(radians(`naarpllat`))*cos(radians(`naarpllng`)-radians(4.2871622))+sin(radians(51.4945758))*sin(radians(`naarpllat`)))) AS verschil FROM ritten force index (naarpositie) WHERE vraag_aanbod like 'A%' AND naarpllat < 51.1350256549 AND naarpllat > 50.8649743451 AND naarpllng < 4.2140244802 AND naarpllng > 3.7859755198 AND vertrekdatum >= '2011-07-12' HAVING verschil <= 15
So, in my opinion the input is the same, the formulas are the same and the outcome is different. Thats is because the lat and lng are handled in the calcultation as integers without decimals.
What is the address you are using? What is the XML you are getting?
> $geo = new SimpleXMLElement(file_get_contents($url));
> usleep(1750000);
> if ($geo->status == "OK") {
> $naarposlat = $geo->result->geometry->location->lat; // = 51.4945758 in the
> calculation this is handled as 51 ???
So the only difference is how $naarposlat is derived. One is set via a
$_GET parameter? And the other is derived from the XML.
I think I concur with Rossko: either something is broken or there are
issues with commas and points and internationalisation. $naarposlat
would be handled as an integer if the decimal character is not what is
expected.
I still reckon it's an internationalisation problem -- that's exactly
the behaviour which will be seen if your decimal point is an
unexpected character. And it's a PHP issue, not a Maps problem per se.