开发者

Convert float latitude and longitude into geography

How to convert float latitude and longitude values into geography type value? I have @lat and @lon variab开发者_如何学Cles.


With case statement:

CASE
    WHEN ((@Latitude IS NOT NULL) AND (@Longitude IS NOT NULL))
    THEN geography::Point(@Latitude, @Longitude, 4326)
    ELSE NULL           
END

or a variant with if:

 DECLARE @Location geography = NULL
 IF (@Latitude IS NOT NULL AND @Longitude IS NOT NULL)
    SET @Location = geography::Point(@Latitude, @Longitude, 4326);


I've found solution by myself:

geography::STPointFromText(
    'POINT(' + CAST(@lon AS VARCHAR(20)) + ' ' + CAST(@lat AS VARCHAR(20)) + ')', 4326)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜