http://en.wikipedia.org/wiki/Geohash
简单使用 geohash, redis,bottle, python-geohash 来实现 restful api的地理位置附近人搜素
from bottle import Bottle, run
import time
import json
from redis_pool import Redis
R = Redis().connection_pool()
import geohash
app = Bottle()
@app.route('/v1/mark/<longitude:float>/<latitude:float>')
def mark_police(longitude, latitude):
geo_encode = geohash.encode(longitude, latitude, 12)
R.set(geo_encode, time.time())
return json.dumps({"code":"success", "msg":{"geohash":geo_encode}})
@app.route('/v1/show/<longitude:float>/<latitude:float>')
def show(longitude, latitude):
geo_encode = geohash.encode(longitude, latitude, 7)
eight = geohash.expand(geo_encode)
response = []
for e in eight:
response.extend([geohash.decode(i) for i in R.keys("%s*"%e)])
return json.dumps({"code":"success", "msg":response})
run(server='eventlet', app=app, host='0.0.0.0', port=9090)
依赖的redis封装class
import redis
class Redis(object):
pool=None
R = None
def __init__(self, host='localhost', port=6379, max_connections=2048):
self.host=host
self.port=port
self.max_connections=int(max_connections)
self.pool = redis.ConnectionPool(host=host,
port=port, db=0,
max_connections=max_connections)
def connection_pool(self):
if not self.R:
self.R = redis.Redis(connection_pool=self.pool)
return self.R
API 接口使用example
1. 标记 user 位置
http://localhost:9090/v1/mark/longitude/latitude
example:
http://localhost:9090/v1/mark/12.1256/22.22
{"msg": {"geohash": "s6pucxkhex8v"}, "code": "success"}
2. 用户请求周围1km内的 其他 user 位置信息
http://localhost:9090/v1/show/longitude/latitude
example:
http://localhost:9090/v1/show/12.1256/22.22
{"msg": [[12.123455917462707, 22.220000009983778], [12.125600008293986, 22.220000009983778]], "code": "success"}
注:
longitude 经度
latitude 纬度
均为float 型
分享到:
相关推荐
geohash解决计算附近距离,搜索附近的商业点,两个经纬度距离,地理位置应用处理
1)GeoHash用一个字符串表示经度和纬度两个坐标,比如我现在所在位置的GeoHash值为 wx4sv61q; 2)GeoHash标识的并不是一个点,而是一个区域,比如 wx4sv61q 对应的就是一个矩形区域; 3)编码的前缀可以标识更大...
非常使用的 基于geohash 找一定范围内的 最近位置java代码
geohash官方发布以及maven发布的版本都是基于jdk1.7编译的,碰到jdk1.6的项目会报unsupported major.minor version 51.0错误。这个资源是我基于jdk1.6编译的,执行测试案例都通过了。
项目中使用的 GEOhash 算法, 在网上公开的GEOhash demo基础上, 做了升级, 功能: 1. 根据指定坐标生成 GEOhash对象 2. 根据当前坐标(GEOhash对象)获取周边8/9个GEOhash对象 3. [升级]根据当前坐标获取指定半径...
Laravel开发-geohash 此包geohash支持laravel 5。
nodejs 根据经纬度计算geohash
laravel_geohash在laravel中使用geohash实现附近的功能随着附近的X ,越来越实用。很多APP都加入了该功能,那么它该怎么实现?在php中如何使用。首先可以参考:环境laravel 5.8使用距离假设,使用手机获取到经纬度 ...
geohash解决计算附近距离,搜索附近的商业点,两个经纬度距离,地理位置应用处理
根据gps计算geohash、根据一个geohash获取周围8个geohash'值,计算两点gps的距离,根据一点gps、方位角和距离计算另一点gps,WGS-84坐标系和GCJ-02坐标系互转,计算geohash区域中心点gps的工具
Geohash算法实现,经纬度到geohash编码的实现
如何找到周围8个区域的GeoHash编码, java版本的。
网上有很多geohash算法的实现,都是基于java或者php代码实现的,没有sql实现的版本,这里使用mysql简单实现了这个算法
GeoHash将二维的经纬度转换成字符串
利用 Geohash 技术建地图索引,比传统的经纬度索引及 spatial 索引效率更高。 这是基于 Javascript 的geohash 实现,并实现了相邻的块的计算。
geohash, php生成类 geohash这年头和LBS相关的应用越来越火。从foursquare的热闹程度就可见一般。更不用说微信、陌陌了( 什么,没听过 foursquare 。 。哥们。LBS有关的应用一般都包括一些共同的操作。最常见的一个...
数据更新于:2020年11月06日 ,包含4个json(省级、地级、县级、乡级),3个整理后的txt,1个java文件 带注释,具体可看文章:https://mp.csdn.net/editor/html/115234415
Geohash-1.0-py2.7 python计算geohash值转换为经纬度
移动互联网,lbs可以说是一个基础应用,geohash对于解决附近地点搜索提供了一个有效的解决方案。扩展: 这个php扩展,提供了三个函数:/** * $latitude //纬度 * $longitude //经度 * $precision //...
Geohash算法就是将经纬度编码,将二维变一维,给地址位置分区的一种算法 此檔案為C語言實現 函式庫使用介紹: 1)編碼 char* geohash_encode(double lat, double lng, int precision); 以所需精度獲取緯度和經度並...