我有多行度数分秒,需要用查询转换.
36°19’11.46“ N = 36.31985
95°36’02.22“ W = 95.600617
每行将有所不同.我已经坚持了两天.这有可能吗?
解决方法:
不错的Lifehack:使用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