我有多行度分秒,需要通过查询进行转换。
36°19'11.46"N = 36.31985
95°36'02.22"西经 = 95.600617
每一行都会不同。我已经被这个问题困扰了两天了。这可能吗?
最佳答案
不错的生活窍门:使用 SEC_TO_TIME 内置 MySQL 函数逆向问题解决方案(程度为 DMS):
CREATE FUNCTION `geocoords`(lon double, lat double) RETURNS varchar(24) CHARSET cp1251
NO SQL
DETERMINISTIC
begin
declare alon double;
declare alat double;
declare slon varchar(12);
declare slat varchar(12);
set alon = abs(lon);
set alat = abs(lat);
set slon = TIME_FORMAT(SEC_TO_TIME(alon*3600), '%H°%i''%s"');
set slat = TIME_FORMAT(SEC_TO_TIME(alat*3600), '%H°%i''%s"');
if lon>0 then
set slon = concat(slon, 'E');
elseif lon<0 then
set slon = concat(slon, 'W');
end if;
if lat>0 then
set slat = concat(slat, 'N');
elseif lat<0 then
set slat = concat(slat, 'S');
end if;
return concat(slat, ' ', slon);
end
SELECT geocoords(30.550157546997, 50.344024658203)
50°20'38"N 30°33'01"E
关于MySQL 将度、分、秒转换为十进制数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27868228/