mysql 根据经纬度查询范围点
一.根据经纬度查询一定范围内所有点
mybatis写法
<select id="selectPtStoreList" parameterType="PtStore" resultMap="PtStoreResult">selectid,store_no,store_name,open_id,store_image,store_img_url,province,city,district,county,Community,address,id_no,longitude,latitude,store_category_id,tel,phone,busno,store_status,synopsis,store_type,ranks,create_time,update_time<if test="longitude != null and longitude != '' and latitude != null and latitude != ''">,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN((#{latitude} * PI() / 180 - latitude * PI() / 180) / 2),2) + COS( #{latitude} * PI() / 180) * COS(latitude * PI() / 180) * POW(SIN((#{longitude} * PI() / 180 - longitude * PI() / 180) / 2),2))) * 1000) AS m</if>from pt_store<where><if test="storeNo != null and storeNo != ''"> and store_no = #{storeNo}</if><if test="storeName != null and storeName != ''"> and store_name like concat('%', #{storeName}, '%')</if><if test="openId != null and openId != ''"> and open_id = #{openId}</if><if test="storeImage != null and storeImage != ''"> and store_image = #{storeImage}</if><if test="storeImgUrl != null and storeImgUrl != ''"> and store_img_url = #{storeImgUrl}</if><if test="province != null and province != ''"> and province = #{province}</if><if test="city != null and city != ''"> and city = #{city}</if><if test="district != null and district != ''"> and district = #{district}</if><if test="county != null and county != ''"> and county = #{county}</if><if test="community != null and community != ''"> and Community = #{community}</if><if test="address != null and address != ''"> and address = #{address}</if><if test="idNo != null and idNo != ''"> and id_no = #{idNo}</if><if test="longitude != null and longitude != '' and latitude != null and latitude != ''"> and(acos(sin(( #{latitude} * 3.1415 )/ 180 ) * sin(( latitude * 3.1415 )/ 180 ) + cos(( #{latitude} * 3.1415 )/ 180 ) * cos(( latitude * 3.1415 )/ 180 ) * cos(( #{longitude} * 3.1415 )/ 180 - ( longitude * 3.1415 )/ 180 ))* 6370.996)<=3</if><if test="storeCategoryId != null "> and store_category_id = #{storeCategoryId}</if><if test="tel != null and tel != ''"> and tel = #{tel}</if><if test="phone != null and phone != ''"> and phone = #{phone}</if><if test="busno != null "> and busno = #{busno}</if><if test="storeStatus != null "> and store_status = #{storeStatus}</if><if test="synopsis != null and synopsis != ''"> and synopsis = #{synopsis}</if><if test="storeType != null "> and store_type = #{storeType}</if><if test="ranks != null "> and ranks = #{ranks}</if></where>order by ranks desc</select>
sql
SELECTid,store_no,store_name,open_id,store_image,store_img_url,province,city,district,county,Community,address,id_no,longitude,latitude,store_category_id,tel,phone,busno,store_status,synopsis,store_type,ranks,create_time,update_time,ROUND(6378.138 * 2 * ASIN(SQRT(POW( SIN( ( 46.577759 * PI() / 180 - latitude * PI() / 180 ) / 2 ), 2 ) + COS( 46.577759 * PI() / 180 ) * COS( latitude * PI() / 180 ) * POW( SIN( ( 125.166985 * PI() / 180 - longitude * PI() / 180 ) / 2 ), 2 ) ) ) * 1000 ) AS m from pt_store
WHERE(acos(sin(( 46.577759 * 3.1415 )/ 180 ) * sin(( latitude * 3.1415 )/ 180 ) + cos(( 46.577759 * 3.1415 )/ 180 ) * cos(( latitude * 3.1415 )/ 180 ) * cos(( 125.166985 * 3.1415 )/ 180 - ( longitude * 3.1415 )/ 180 ) )* 6370.996 )<= 3 limit 0, 1
二 取范围内最近距离
SELECT`id`,`province`,`city`,`district`,`county`,`Community`,`ranks`,`address`,`longitude`,`latitude`,`switchs`,`create_time`,`update_time`,(6371 * acos (cos ( radians( 125.161258 ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( 46.571054 ) ) + sin ( radians( 125.161258 ) ) * sin( radians( latitude ) ) ) ) AS distance
FROMjs_estate
HAVING1.6 > distance
ORDER BYdistance LIMIT 0,1;
1.6公里数
mysql 根据经纬度查询范围点相关推荐
- mysql根据经纬度查询范围内数据,并根据距离排序
最近接到一个新需求,要根据经纬度查询指定范围内的数据,并且根据距离进行排序,网上找了找相关实现方法,记录一下. java代码如下 public final class DistanceUtils {/ ...
- mysql 根据经纬度查询规定范围内符合坐标的店铺并优化查询的sql语句
$ lat:纬度, $ lon:经度, 优化查询:latitude < ".($ lat+1)." and latitude> ".($ lat-1).&qu ...
- MySql根据经纬度查询任意距离范围内数据
sql代码#当前位置经纬度 经度:117.215637 纬度:39.1373367 #表中经纬度字段 经度:longitude 纬度:latitude select * from( SELECT id ...
- mysql 根据经纬度查询距离
SELECT*, (6371 * acos(cos(radians('31.82030058')) * cos(radians(lat)) * cos(radians(lng) - radians(' ...
- mysql根据经纬度查询距离在1000米范围内的数据
SELECT lon,lat,id,name, ST_Distance ( point ( lon, lat ), point ( 106.6890580 ...
- mysql根据经纬度查询范围内的数据
distance:范围 lat:纬度 lot:经度 <select id="xx" parameterType="xx" resultType=" ...
- 根据经纬度查询,mysql查询计算经纬度
mysql经纬度查询并且计算2KM范围内附近用户的sql查询性能优化实例教程 https://www.cnblogs.com/mgbert/p/4146538.html
- Mysql实现根据经纬度查询周围的商家,并按距离进行排序
今天要说的是如何在Mysql中实现根据已知的经纬度查询周围的商家(或者是别的带有经纬度字段的表)并且根据距离的远近来进行排序! 废话就不多说了,直奔主题~ 首先有这么个商城表 lng代表经度,lat代 ...
- MySQL之根据经纬度查询多少公里范围内的数据
MySQL之根据经纬度查询多少公里范围内的数据 根据经纬度查询多少公里范围内的数据 创建地址表,存储经纬度信息 插入数据 根据当前经纬度查询所有地址,按距离由近到远排序 查询结果(距离以km为单位) ...
- mysql left join 查询_MySQL联表查询基本操作之left-join常见的坑
概述 对于中小体量的项目而言,联表查询是再常见不过的操作了,尤其是在做报表的时候.然而校对数据的时候,您发现坑了吗?本篇文章就 mysql 常用联表查询复现常见的坑. 基础环境 建表语句 DROP T ...
最新文章
- 图像的读取,显示与保存(基于skimage模块)
- springboot 优雅停机_新姿势,Spring Boot 2.3.0 如何优雅停机?
- 【2019暑假刷题笔记-树的遍历】总结
- 第十一届河南省赛--H : Attack City and Capture Territory
- (资源整理)带你入门Spark
- 国外网站设计欣赏:30个优秀的国外咖啡网站设计
- 正式发布!Azure Functions OpenAPI Extension
- Vue源码解读之事件机制
- 牛客(3)从尾到头打印链表
- 自然语言处理python代码_《自然语言处理入门 Python/Java双代码实现(图灵出品)》(何晗)【摘要 书评 试读】- 京东图书...
- 微信表情html代码大全,微信表情代码
- imdisk虚拟光驱装linux,怎么样通过虚拟光驱装Ubuntu系统?
- 在计算机中这样切换大小英语字母,怎么在Excel2016表格中快速转换字母大小写
- html中多一条黑线,Word页面中上下各有一条黑线怎样去掉?
- springCloud使用redis报错,Could not resolve type id xxxxx(类全路径名) into a subtype
- 局域网流量监控_常见的企业电脑监控网络管理软件哪一款好呢?
- 【电赛练习】手写绘图板 2013电赛G题
- 博客平台遭虚假勒索攻击、新黑客组织称对以色列的攻击负责|11月16日全球网络安全热点
- ERP发货系统的修改(四十三)
- 吴裕雄--天生自然 诗经:声声慢·寻寻觅觅
热门文章
- 机器学习(四):关于模型复杂度与模型性能的关系
- 7-2 单位年会聚餐时的座次C位
- 20172303 2017-2018-2 《程序设计与数据结构》第10周学习总结
- cobalt strick 4.0 系列教程 (5)--- 获取立足点
- 用python生成个性二维码生成器_Python 生成个性二维码
- HDU 1374 求三角形外接圆的半径
- 古月居ROS入门21讲——10-12.Publisher和Subscriber的编程实现 话题消息的定义与使用
- 购物车中我的订单查询
- android u盘加载_[转] android 通过usb读取 U盘
- 领扣LintCode问题答案-5. 第k大元素