How to represent geographical locations

社会主义新天地 提交于 2019-12-04 18:47:19

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.

Why not just do:

<option value="{lat:-22.45,long:-43.12,r:294200}">Rio De Janeiro</option>

Then you can jsondecode the value to get the components of it.

Most likely you look for a quadkey. A quadkey is a spatial index or a space-filling-curce. It looks like a quadtree or a fractal and reduce the 2d complexity to a 1d complexity. Google-Maps and Bing-Maps are using a z-curve because it's easy to solve. A hilbert-curve is better at space filling but more difficult to solve. The idea of a quadkey is to search for a tile and its locations from left to right. For example if your quadkey is 12333222244 you can search for 1233* and you get all locations from that tile and after or below that tile because it's a tree data structure.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!