开发者

A good way to make Django geolocation aware? - Django/Geolocation

I would like to be able to associate various models (Venues, places, landmarks) with a City/Country.

But I am not sure what some good ways of implementing this would be.


I'm following a simple route, I have implemented a Country and City model.

Whenever a new city or country is mentioned it is automatically created.

Unfortunately I h开发者_运维百科ave various problems:

  • The database can easily be polluted

  • Django has no real knowledge of what those City/Countries really are


Any tips or ideas? Thanks! :)


A good starting places would be to get a location dataset from a service like Geonames. There is also GeoDjango which came up in this question. As you encounter new location names, check them against your larger dataset before adding them. For your 2nd point, you'll need to design this into your object model and write your code accordingly.

Here are some other things you may want to consider:

  • Aliases & Abbreviations
    • These come up more than you would think. People often use the names of suburbs or neighbourhoods that aren't official towns. You can also consider ones like LA -> Los Angeles MTL for Montreal, MT. Forest -> Mount Forest, Saint vs (ST st. ST-), etc.
  • Fuzzy Search
    • Looking up city names is much easier when differences in spelling are accounted for. This also helps reduce the number of duplicate names for the same place.
    • You can do this by pre-computing the Soundex or Double Metaphone values for the cities in your data set. When performing a lookup, compute the value for the search term and compare against the pre-computed values. This will work best for English, but you may have success with other romance language derivatives (unsure what your options are beyond these).
  • Location Equivalence/Inclusion
    • Be able to determine that Brooklyn is a borough of New York City.

At the end of the day, this is a hard problem, but applying these suggestions should greatly reduce the amount of data corruption and other headaches you have to deal with.


Geocoding datasets from yahoo and google can be a good starting poing, Also take a look at geopy library in django.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜