How to calculate nearby distance from latitude and logitude?

hi
i having a current location latitude and logtitude, i want to get the nearest cities within 25 km. how to calculate. guide me to solve problem

you got list of cities yourself?

We cannot do the work for you, we can only offer helpful suggestions to get you pointed in the right direction.

Let me give you a hand on this: Let me google that for you

i know.i got that ,thank you, your blog post is very useful to me . thanks for all who make support to solve this problem.

Assuming you have a list of cities you want to check against, that’s simple geometry.

\$citylist should be an array of arrays indexed by city name containing longitudes and latitudes in degrees.

``````
function nearestCities(\$originLatitude,\$originLongitude,\$maxDistance) {
\$resultList=array();
foreach (\$cityList as \$cityName => \$city) {
\$spheric=(
);
// diameter of earth = 7,926.3352 miles
\$distance=7926.3352*atan2(sqrt(\$spheric),sqrt(1-\$spheric));
if (\$distance<=\$maxDistance) {
\$resultList[]=array(
'cityName' => \$cityName,
'distance' => \$distance
)
}
}
return \$resultList;
}

``````

Untested, not entirely accurate (no deformation adjustment), but should do the job… assuming you have a list of all relevant cities to run it up against. The “great-circle distance” page on wikipedia is cute, but it’s all non-code theory and takes a bit of gutting to turn it into something useful. (and to kick those metric…)

Just thought code might be more useful than vague/cryptic formulas – it’s why I hated geometry and calculus; cryptic symbols might be cute when doing this stuff on a blackboard, but should have gone the way of the dodo decades ago in favor of SHOCK actual words to describe things. To me it’s one of those things designed to intentionally make such subjects hard. (But again, I’m a Wirth fan)

I seem to be in the minority on that one though. (like a great many things)