Question

I'm using a haversine query to pull locations nearest to a lat/lon provided from a mobile app.

The query looks like this:

SELECT *,(((acos(sin(($latitude *pi()/180)) * sin((`lat`*pi()/180))+cos(($latitude *pi()/180)) * cos((`lat`*pi()/180))* cos((($longitude - `lon`)*pi()/180))))*180/pi())*60*1.1515) AS dist_x 
FROM `work_places`
HAVING dist_x <= '1'
ORDER BY dist_x ASC
LIMIT 10

This is working just fine and I'm getting exactly the locations I should be getting.

The problem is in converting dist_x to something readable by the users. Right now, lets say dist_x reads as: 0.00996273036944 (floatval and as a string shows the same so it's converting properly)

Since the query is searching withing 1 mile, I am trying to convert this to feet so I'm dividing dist_x by 5280.

       $distance = (float)( $dist_x / 5280 );

What I get back is $distance = 1.88688075179E-6

What am I doing wrong?

Was it helpful?

Solution

I may be missing something, but if you want to convert miles to feet, don't you want to multiply by 5280 instead of dividing?

OTHER TIPS

A mile is 5280 feet, so it should be

$distance = (float)( $dist_x * 5280 );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top