栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

mysql 根据经纬度查询范围点

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mysql 根据经纬度查询范围点

一.根据经纬度查询一定范围内所有点

mybatis写法 

  
    select
        id,
        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(
            (
            #{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
        
        from pt_store
        
             and store_no = #{storeNo}
             and store_name like concat('%', #{storeName}, '%')
             and open_id = #{openId}
             and store_image = #{storeImage}
             and store_img_url = #{storeImgUrl}
             and province = #{province}
             and city = #{city}
             and district = #{district}
             and county = #{county}
             and Community = #{community}
             and address = #{address}
             and id_no = #{idNo}
             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
             
             and store_category_id = #{storeCategoryId}
             and tel = #{tel}
             and phone = #{phone}
             and busno = #{busno}
             and store_status = #{storeStatus}
             and synopsis = #{synopsis}
             and store_type = #{storeType}
             and ranks = #{ranks}
        
        order by ranks desc
    

sql 

SELECT
	id,
	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 
FROM
	js_estate 
HAVINg
	1.6 > distance 
ORDER BY
	distance 
	LIMIT 0,
	1;

1.6公里数

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/904968.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号