加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – DbGeography.PointFromText 24141:预计位置上有

发布时间:2020-12-12 06:28:26 所属栏目:MsSql教程 来源:网络整理
导读:我有WCF REST服务,其中包含以下代码 var geo = DbGeography.PointFromText(string.Format("POINT({0} {1})",longitude,latitude),DbGeography.DefaultCoordinateSystemId); 单元测试工作正常,但是当我从客户端或HTTP debuder调用此代码时,提供纬度和经度的任
我有WCF REST服务,其中包含以下代码
var geo = DbGeography.PointFromText(string.Format("POINT({0} {1})",longitude,latitude),DbGeography.DefaultCoordinateSystemId);

单元测试工作正常,但是当我从客户端或HTTP debuder调用此代码时,提供纬度和经度的任何值exept 0,它会失败,但异常:

"24141: A number is expected at position X of the input. The input has,XXXXXX."
   at Microsoft.SqlServer.Types.WellKnownTextReader.RecognizeDouble()
   at Microsoft.SqlServer.Types.WellKnownTextReader.ParsePointText(Boolean parseParentheses)
   at Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType type)
   at Microsoft.SqlServer.Types.WellKnownTextReader.Read(OpenGisType type,Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.ParseText(OpenGisType type,SqlChars taggedText,Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type,Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.STPointFromText(SqlChars pointTaggedText,Int32 srid)

纬度和例如
纬度:37.58336895长:-122.40549454
纬度:37.38931302长:-122.16207476

我使用从SQLServer安装目录和SqlGeography.Point引用的Microsoft.SqlServer.Types来处理代码端的spartial数据.现在我想直接使用EF 5功能,而不使用对Microsoft.SqlServer.Types的引用.它有没有这个参考就失败了.

知道什么是错的吗?

安装了.NET 4.5,SQL Server版本是
Microsoft SQL Server 2008(SP3) – 10.0.5500.0(Intel X86)2011年9月22日00:28:06版权所有(c)1988-2008 Microsoft Corporation在Windows NT 6.1上的标准版(Build 7601:Service Pack 1)

解决方法

您必须在连接之前使用invariantCulture转换坐标.
String lon = longitude.ToString(CultureInfo.InvariantCulture);
  String lat = latitude.ToString(CultureInfo.InvariantCulture);
  var geo = DbGeography.PointFromText(string.Format("POINT({0} {1})",lon,lat),DbGeography.DefaultCoordinateSystemId);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读