使用sql定位位置 [英] locating places using sql

查看:127
本文介绍了使用sql定位位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有人能帮我解决这个mysql查询吗?

我需要用经度和300度找出我周围300m的地方伦敦地区的态度。

我的数据如下:

我所在地的名称

atitude

经度

邮政编码

row和col是用于在网格中给出唯一位置的数字。



从我到目前为止所理解的是,我需要将纬度和经度转换为m,然后尝试找出总纬度和经度并抽象它的距离?

任何建议都是赞赏

谢谢

解决方案

尝试创建此UDF的变体我用来确定KM的距离。



 创建 功能 [dbo] 。[距离]( @ lat1   float , @ long1   float  @ lat2   float  @ long2   float 
返回 float
< span class =code-keyword> as
begin
/ * ************************************* ***************************************
名称 - 距离
对象类型 - 用户定义函数
创建日期 - 2010年9月15日
作者 - Tim Keen

描述 - 给定十进制度格式的两个位置的纬度和经度,
返回位置之间的距离(以千米为单位)。
********************************************** *********************************** /

声明 @ DegToRad as float
声明 @ MilesToKm as float
声明 @ Ans as float
声明 @ Miles as float
声明 @ Kms as float

set @ DegToRad = 57 29577951
set @ MilesToKm = 1 609344
set @ Ans = < span class =code-digit> 0
set @ Miles = 0

if @ lat1 null < span class =code-sdkkeyword> @ lat1 = 0 @ long1 null Ò r @ long1 = 0 @ lat2
null @ lat2 = 0 < span class =code-keyword>或 @ long2 null @ long2 = 0
开始
return @ Miles
end
set @ Ans = SIN(@ lat1 / @ DegToRad)* SIN(@ lat2 / @ DegToRad)+ COS(@ lat1 / @ DegToRad)* COS(@ lat2 / @ DegToRad)* COS(ABS( @ long2 - @ long1 )/ @ DegToRad)
< span class =code-keyword> set @ Miles = CEILING( 3959 * ATAN (SQRT( 1 - SQUARE( @ Ans ))/ @ Ans))
set @ Kms = @ Miles * @ MilesToKm
return @ Kms


Hi
could anyone help me with this mysql query please?
I need to find out the places that are around me within 300m using longitude and attitude within London areas.
the data I have is as follow :
name of the place where I am based
atitude
longitude
postcode
row and col are numbers used for giving a unique position in the grid .

From what I understood so far is that, i need to convert the latitude and longitude into m, then try to find the total latitude and longitude and abstract the distance from it?
Any suggestion is appreciated
Thank you

解决方案

Try creating a variation of this UDF I use to determine distance in KM.

CREATE function [dbo].[Distance]( @lat1 float , @long1 float , @lat2 float , @long2 float)
returns float
as
begin
/*****************************************************************************
Name		 -	Distance
Object type	 -	User Defined Function
Created Date -	15 Sep 2010
Author		 -	Tim Keen

Description	 -	Given the latitude and longitude of two locations in decimal degrees format, 
				returns the distance in kilometers between the locations. 
*********************************************************************************/
	declare @DegToRad as float
	declare @MilesToKm as float
	declare @Ans as float
	declare @Miles as float
	declare @Kms as float

	set @DegToRad = 57.29577951
	set @MilesToKm = 1.609344
	set @Ans = 0
	set @Miles = 0

	if @lat1 is null or @lat1 = 0 or @long1 is null or @long1 = 0 or @lat2 is
	null or @lat2 = 0 or @long2 is null or @long2 = 0
		begin
			return ( @Miles )
		end
	set @Ans = SIN(@lat1/@DegToRad) * SIN(@lat2/@DegToRad) + COS(@lat1/@DegToRad ) * COS( @lat2/@DegToRad ) * COS(ABS(@long2 - @long1)/@DegToRad)
	set @Miles = CEILING(3959 * ATAN(SQRT(1 - SQUARE(@Ans))/@Ans))
	set @Kms = @Miles * @MilesToKm
	return (@Kms)


这篇关于使用sql定位位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆