1.腾讯位置服务 WebService API | 腾讯位置服务
-
申请开发者密钥(Key):申请密钥。
-
Hello world:本示例的Key仅为演示使用,实际开发及上线时,请务必使用您申请的Key。以下示例为:搜坐标位置周边1000米范围内,关键字为“酒店”。
https://apis.map.qq.com/ws/place/v1/search?keyword=酒店&boundary=nearby(39.908491,116.374328,1000)&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77
2.获取要查找地址的经纬度
public function address(){
try {
//获取经纬度
$lat = request()->get('lat');
$lng = request()->get('lng');
//调用第三方获取周边信息
$message = file_get_contents("https://apis.map.qq.com/ws/place/v1/search?keyword=学校&boundary=nearby($lat,$lng,1000)&key=BR5BZ-2XUES-O5HOT-62FWR-LFWZJ-ARFLN");
$message=json_decode($message,true)['data'];
//周边景点存入redis
foreach ($message as $v){
Redis::rawCommand('geoadd','address',$v['location']['lng'],$v['location']['lat'],$v['title']);
}
//计算两点排序
$data = Redis::rawCommand('GEORADIUS','address',$lng,$lat,'1000','km','withdist','asc');
if (!$data){
return json_encode(['code'=>200,'msg'=>'排序成功','data'=>$data]);
}
return json_encode(['code'=>200,'msg'=>'排序成功','data'=>$data]);
}catch (\Exception $exception){
return json_encode(['code'=>2001,$exception->getMessage(),'data'=>'']);
}
}
3.效果图
Redis一些低版本是用不了GEO的,如我是用的5.0版本就可以使用