laevael 7 使用redis 中geo 类型计算两地之间的距离
2021/12/11 19:49:44
本文主要是介绍laevael 7 使用redis 中geo 类型计算两地之间的距离,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
public function redis(Request $request){ //$city地区1 //$goodsCity地区2 $city=$request->input('city'); $goodsCity=$request->input('goodsCity'); //地址改为经纬度 调用百度地图 $url='http://apis.map.qq.com/ws/geocoder/v1/?address='.$city.'&key=你申请的百度地图key'; $result=file_get_contents($url); $data = json_decode($result,TRUE); //经纬度 取值 // var_dump($data['result']['location']['lng']); // var_dump($data['result']['location']['lat']); //地址改为经纬度 调用百度地图 $url='http://apis.map.qq.com/ws/geocoder/v1/?address='.$goodsCity.'&key=ZSYBZ-RF6RK-RONJP-AZYJM-BQBKQ-4OB3J'; $result=file_get_contents($url); $res = json_decode($result,TRUE); //经纬度 取值 // var_dump($res['result']['location']['lng']); // var_dump($res['result']['location']['lat']); Redis::geoAdd('citys', $data['result']['location']['lng'], $data['result']['location']['lat'], $city); Redis::geoAdd('citys', $res['result']['location']['lng'], $res['result']['location']['lat'], $goodsCity); $data=Redis::geodist( 'citys','beijing', 'shanghai','km'); return ['code'=>200,'data'=>'两地距离'.$data.'km','msg'=>'ok']; } redis 版本必须是3.2 以上
这篇关于laevael 7 使用redis 中geo 类型计算两地之间的距离的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-31Tiny RDM:你的下一代Redis桌面GUI神器-icode9专业技术文章分享
- 2024-03-21redisinsight-v2
- 2024-02-26Typed property App\Api\Mapper\GamePropsConfigMapper::$apiRedis must not be accessed before initia-icode9专业技术文章分享
- 2024-02-21redisson getlock
- 2024-02-20redis config
- 2024-02-20redis leaderboard
- 2024-01-23缓存选型:Redis or MemCache
- 2024-01-22面试官:Redis持久化能关吗?怎么关?
- 2024-01-21Redis压测工具redis-benchmark-icode9专业技术文章分享
- 2024-01-19这才是你应该了解的Redis数据结构!