开发者

How to get the closest significant population centre from a latitude and longitude?

I'm currently tryi开发者_如何转开发ng to reverse geocode a series of lat/long co-ordinates using the Virtual Earth/Bing Maps web services. Whilst I can successfully retrieve an address for the positions I also need to be able to retrieve the closest significant population centre for the position so I can display a heading and distance to the centre of the nearest town/city/metropolis etc. This is for cases where the location is travelling between locations e.g. on a highway/motorway.

Has anyone out there got any ideas how to do this as I've been banging my head against it for a few days now and I've gotten nowhere!

Cheers in advance...


I think it is safe to assume that the nearest city is always quite close compared with the size of the Earth, so you can use a simple pythagoras triangle.

Suppose you are at (lat0, long0) and a trial city is at (lat1, long1).

Horizontal (EW) distance is roughly

d_ew = (long1 - long0) * cos(lat0)

This is multiplied by cos(lat0) to account for longitude lines getting closer together at high latitude.

Vertical (NS) distance is easier

d_ns = (lat1 - lat0)

So the distance between the two points is

d = sqrt(d_ew * d_ew + d_ns * d_ns)

You can refine this method for more exacting tasks, but this should be good enough for the nearest city.

For comparing distances, it will be fine to compare d squared, which means you can omit the sqrt operation.


try using the wikipedia location service, documented here http://www.geonames.org/export/wikipedia-webservice.html


It sounds like you're looking for a database of latitudes and longitudes of major cities, so you can calculate distances.

This is a link to a page giving a few dozen, world-wide.

There may be others, most likely US-centric (but that may be what you want).


I would do the following:

table 1:

T_CityPopulation

Fields:

CityTownInfo,Population,LonLat

Then compute distance between your current LonLat for each record in table 1, using a threshold value ignore towns/citys over x miles. Then sort the results by Population.

EDIT:

Even if you don't want to maintain a table, it has to be stored somewhere, I think if you maintained it yourself at least you have control over it, vs relying on another service.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜