如何表示地理位置 [英] How to represent geographical locations

查看:132
本文介绍了如何表示地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让用户界面看起来增加了与facebook的集成,并且可以将搜索与类别和位置结合起来:


这对我来说不仅带来了facebook集成,还带来了一些问题位置。我不会从数据存储中获取位置,我只是将它们放在纯html中:

 < select name =w id =searcharea> 
< option value =1>整个印度< / option>
< option value =2>安达曼&尼科巴群岛< / option>
< option value =3>安得拉邦< / option>

等。我们看到期权价值没有意义:1,2,3没有意义,我只是把数字放在那里。数据存储区中的记录可以基于经度+纬度+半径来匹配,因此例如像?lat = -22.45& lon = -43.12& r = 294200 的URL是与里约热内卢的周围环境相匹配的参数化,在这种情况下半径有点随意选择以匹配里约热内卢而不是圣保罗。将经度和纬度四舍五入至小数点后2位也被认为足够好。但是,如何在HTML和数据存储之间进行映射? HTML选项值只有一个值,经度+纬度+半径是三个值。我想找到一个涵盖所有内容的解决方案,无需添加我自己的地理代码。经度,纬度和半径是国际标准,所以自然我希望避免为地点创建我自己的ID。我可能会做一个算法,选项值的值是一个数字解码为三个值,例如选项值123456789876将解码为经度1234,纬度5678和半径9876.你能推荐任何解决方案和/或告诉我其他可能的解决方案有哪些优点和缺点?如果您想检查我所说的网站,可以通过此链接koolbusiness.com



我想与其他解决方案(如geomodel和google maps)保持兼容,以便用户可以选择行政区域,城市,国家以一种兼容谷歌地图的方式,因为他们已经创建并更新了结构和比赛,而我已经使用Python库geomodel为我的实体启用了地理位置:

  class A(GeoModel,search.SearchableModel):
primary_image = blobstore.BlobReferenceProperty()
postaladress = db.PostalAddressProperty(indexed = False,verbose_name =postaladdress )
...

使用geomodel实现基本搜索:

  m = int(self.request.get('r'))if self.request.get('r')else 804670#radius 
lat = self.request.get('lat')
lon = self.request.get('lon')
articles = A.proximity_fetch(A.all(),db.GeoPt(lat,lon),max_results = PAGESIZE + 1,max_distance = m)
articles = sorted(articles,key = lambda x:x.modified,reverse = True)

但是如何将视图与后端集成,因为选项值只允许单个值?我应该编码3个值(lon,lat,radius)编码为单个值吗?或者其他解决方案?
谢谢

解决方案

最简单的方法是在您的配置文件中定义查找表码。例如:

  location_map = {
1:{'name':Rio De Janeiro','lat': -22.45,'long':-43.12,'radius':294200},
#...
}

然后,您可以简单地使用选项值作为查找数组中值的键。您也可以使用这个数组来生成表单字段,方法是遍历它并输出名称/值对。


I make the user interface appear adding integration with facebook and enabling combining a search with a category and a location:

This poses some problems to me not only with the facebook integration but also with locations. I don't fetch the locations from the datastore, I just put them in plain html:

<select name="w" id="searcharea">    
<option value="1" >Entire India</option>            
<option value="2" > Andaman & Nicobar Islands</option>          
<option value="3" > Andhra Pradesh</option>

etc. We see that the option values make no sense: 1,2,3 has no meaning and I just put the numbers there. The records in the datastore can match based on longitude+latitude+radius so for instance an URL like ?lat=-22.45&lon=-43.12&r=294200 is a parametrization that matches Rio de Janeiro with surroundings where the radius is a bit arbitrarily chosen in this case to match Rio de Janeiro and not Sao Paulo. Rounding off the longitudes and latitudes to 2 decimals is also decided as "good enough". But how do I map between the HTML and the datastore? An HTML option value has only one value and longitude + latitude + radius are three values. I'd like to find a solution that covers everything without needing to add my own geography codes. Longitude, latitude and radius are international standard so naturally I wish to avoid creating my own IDs for locations. I probably could make an algorithm that the value of the option value is one number that decodes to three values for instance the option value 123456789876 would decode to longitude 1234, latitude 5678 and radius 9876. Can you recommend any solution and/or tell me other advantages and disadvantages the possible solutions have? If you want to inspect the website I talk about, you can via this link koolbusiness.com

I'd like to stay "compatible" with other solutions such as geomodel and google maps so also allowing user to select an "administrative area", a "city", a "country" in a way compatible with google maps since they already make and update that structure and its contens while I've used the python library geomodel to enable a geography for my entities:

class A(GeoModel,search.SearchableModel):      
    primary_image=blobstore.BlobReferenceProperty() 
    postaladress=db.PostalAddressProperty(indexed=False,verbose_name="postaladdress")
    ...

Implementing a basic search with geomodel works:

m=int(self.request.get('r')) if self.request.get('r') else 804670#radius
lat = self.request.get('lat')
lon = self.request.get('lon')
articles = A.proximity_fetch(A.all(),db.GeoPt(lat, lon),max_results=PAGESIZE+1, max_distance=m)
articles = sorted(articles, key=lambda x: x.modified, reverse=True)

But how integrate the view with the backend since the option value only admit a single value? Should I encode 3 values (lon,lat,radius) encoded as a single value? Or some other solution? Thank you

解决方案

The easiest way to do this would be to define a lookup table in a configuration file in your code. For instance:

location_map = {
  1: {'name': Rio De Janeiro', 'lat': -22.45, 'long': -43.12, 'radius': 294200},
  # ...
}

Then, you can simply use the option value as the key you look up the values in the array by. You can also use this array to generate the form field by iterating over it and outputting name/value pairs.

这篇关于如何表示地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆