Pergunta

Considering a radius of 50 KM from the base city i need to find the nearby cities .

My script should be in PHP... Is there any API to find it out....

Please please help me...

THanks...

Foi útil?

Solução

This is a great resource: code.google.com/apis/maps/articles/phpsqlsearch.html#findnearsql

Base city:   Lat: 37   Lng: -122

SELECT id, ( 6371 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 50 ORDER BY distance LIMIT 0 , 20;

Same principle as the solution from "Tricker".

Outras dicas

I wrote a kind off scripts that calculating distances between coordinates. You can do it when you have 2 coordinates:

base :
 - latitude
 - longitude

city :
 - latitude
 - longititude

You have to pass in the base city geo coords, then you need to send a cURL to the google or yahoo server(depends on which geocoder api you wanna you) to get the city coords.

Now its the question from which cities do you have coordinates? if you have none you can buy a zipcode area database(then you can have your coordinates off the city you wanna have). when you have the coords from city, you can run a complicated calculation as result a distance. After that you can look if the result/distance is greater or lesser then 50. if is lesser you can return it as a city in range.

it isn't something you do in a few minutes

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top