MySQL計算兩座標之間的距離

2021-10-08 23:16:27 字數 1768 閱讀 4793

表結構及資料

drop

table

ifexists

`tb_locationpoint`

;create

table

`tb_locationpoint`

(`id`

int(11)

notnull

auto_increment

,`province`

varchar(20

)not

null

comment

'省份'

,`city`

varchar(20

)not

null

comment

'城市'

,`longitude`

double(10

,3)not

null

comment

'經度'

,`latitude`

double(10

,3)not

null

comment

'緯度'

,primary

key(

`id`))

engine

=innodb

default

charset

= utf8;

insert

into

`tb_locationpoint`

values(1

,'山東'

,'濟南'

,116.938477

,36.597889),

(2,'河北'

,'石家莊'

,114.477539

,38.030786),

(3,'浙江'

,'杭州'

,120.058594

,30.334954),

(4,'河南'

,'鄭州'

,113.629

,34.744),

(5,'安徽省'

,'合肥'

,117.170

,31.520

);

查詢

round函式用於資料的四捨五入,它有兩種形式:

round(x,d),x指要處理的數,d是指保留幾位小數

這裡有個值得注意的地方是,d可以是負數,這時是指定小數點左邊的d位整數字為0,同時小數字均為0;

round(x),其實就是round(x,0),也就是預設d為0;

st_distance為mysql5.6+版本中開始自帶的經緯度計算函式

point在mysql中的point用於表示gis中的地理座標

mysql座標計算 MySQL計算兩座標距離並排序

環境 mysql5.6 表結構及資料 drop table if exists locationpoint create table locationpoint id int 11 not null auto increment,province varchar 20 not null,city v...

Mysql sql 計算兩個座標之間的距離

mysql sql 計算兩個座標之間的距離 赤道半徑 6378.137km 查詢結果為km select id,6378.137 2 asin sqrt pow sin radians 當前緯度latitude radians 資料庫中儲存的目標緯度latitude 2 2 cos radians ...

C OJ習題練習 二十四 求兩座標點之間的距離

problem description 建立乙個二維座標系的類twocoor,用x y表示座標值,計算兩座標點間的距離 你的 將被嵌在這裡 intmain sample output 5解題 匯入相關標頭檔案 include 用於計算的math庫 include using namespace st...