Question

I'm currently trying 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...

Was it helpful?

Solution

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.

OTHER TIPS

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

If you can find a list of coordinates for major population centers, here is some code for computing great circle distances based on coordinates.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top