开发者

How can i get the nearest significant town or city from google maps?

Is this possible?

I have users who will show where they live on a map, if this isn't a large town or city, i'd like to find that开发者_运维问答 and associate this information with the users record.

Any idea how to do this?


Why not use the GeoNames Web Service. You can download the complete dump.

It takes Lat/Lng as parameters and also there is an optional parameter called radius(distance in km) as well as parameter cities where:

cities1000.zip : all cities with a population > 1000 or seats of adm div (ca 80.000)

cities5000.zip : all cities with a population > 5000 or PPLA (ca 40.000)

cities15000.zip : all cities with a population > 15000 or capitals (ca 20.000)columns


I realize this is an old post; however, I'm posting my views for the benefit of the people who stumble upon this post (like I did) in their research.

In order to find the largest/closest large city/town you would need to define 'large'.

  1. What is a large city/town? This is completely subjective - my definition will be different from yours. A mapping service, cannot decide the definition of 'large'.

  2. Priority of large cities? Let's say even if you somehow achieved #1, how will you prioritize. A 'small' town X might have 2 large cities close to it - A & B. Which one would you accept?

Based on the two statements above, I advice you against it; however, if it is impossible for you to avoid this, you would need to put in custom logic in your application. Example: Get all locations within 25 miles and decide for yourself what place you want to save.


I struggled to find the best way to do this for a while. Google's API seems to mostly use addresses/town boundaries when decoding coordinates, which is unhelpful.

If you're in the United States, the National Weather Service's API is perfect. Given coordinates in the US, it can provide the nearest town/census-designated place and the point's distance and direction from the town.

I created a basic site to try it out at https://nearest.town/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜