gps 座標距離計算

 

1)如果是js狀態可以利用地圖供應商比如高德,百度的sdk庫來計算,需要註冊開發者賬號,也可以在其他方式下驗證。

(https://lbs.amap.com/api/javascript-api/example/calcutation/calculate-distance-between-two-markers)

2)利用地球半徑計算。即球體(圓)上2個點的曲線距離。

(https://blog.csdn.net/jianggujin/article/details/72833711)

這個依然是調用第三方高德的接口請求結果。

(https://blog.csdn.net/a_step_further/article/details/54025386)

3.純粹數據庫的計算

mysql(https://blog.csdn.net/jianggujin/article/details/72833711#mysql%E5%AE%9E%E7%8E%B0)

sql server中有關於地理位置的類型,此次傳入參數爲latitude,longititude格式string。

參考(https://stackoverflow.com/questions/13026675/calculating-distance-between-two-points-latitude-longitude#)

ALTER FUNCTION [dbo].[cal_gps_distance]
( @src AS VARCHAR(100),
  @dst AS VARCHAR(100)
)
RETURNS decimal(20,2)
AS
BEGIN
	-- routine body goes here, e.g.
	-- SELECT 'Navicat for SQL Server'
	
	declare @src_lon varchar(50)
	declare @src_lat varchar(50)
	declare @dst_lon varchar(50)	
	declare @dst_lat varchar(50)	
  DECLARE @src_geo geography;
  DECLARE @dst_geo geography;
  DECLARE @result decimal(20,2);

  set @src_lat=convert(decimal(12,9),substring(@src,0,charindex(',',@src)))
  set @src_lon=convert(decimal(12,9),substring(@src,charindex(',',@src)+1,len(@src)))

  set @dst_lat=convert(decimal(12,9),substring(@dst,0,charindex(',',@dst)))
  set @dst_lon=convert(decimal(12,9),substring(@dst,charindex(',',@dst)+1,len(@dst)))
	
	--return @src_lat
	--,@src_lon;
  set @src_geo= geography::Point(@src_lat, @src_lon, 4326);
  set @dst_geo= geography::Point(@dst_lat, @dst_lon, 4326);

  --set @result=convert(decimal(20,2),@src_geo.STDistance(@dst_geo))
	set @result=CAST(@src_geo.STDistance(@dst_geo) as decimal(20,2)) 
	return @result

END

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章