0

最简单的解决方法是什么?

当此代码在澳大利亚(编写它的地方)运行时,它可以工作。

public static void CreatePointTest()
{
  double lat = -33.613869;
  double lon = 153.123456;

  var text = string.Format("POINT({0} {1})", lon, lat);
  // 4326 is most common coordinate system used by GPS/Maps
  var ExceptionOnThisLine = DbGeography.PointFromText(text, 4326);
}

当我将计算机上的区域代码更改为“French (France)”并运行它时,返回语句出现异常,似乎与数字格式相关:

System.Reflection.TargetInvocationException was unhandled  
_HResult=-2146232828   _message=Exception has been thrown by the target of an invocation.   HResult=-2146232828   IsTransient=false   Message=Exception has been thrown by the target of an invocation.   Source=mscorlib   StackTrace:
       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
[snip...]
       InnerException: System.FormatException
       _HResult=-2146233033
       _message=24141: A number is expected at position 16 of the input. The input has ,613869.
       HResult=-2146233033
       IsTransient=false
       Message=24141: A number is expected at position 16 of the input. The input has ,613869.
       Source=Microsoft.SqlServer.Types
       StackTrace:
            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, SqlChars taggedText, Int32 srid)
            at Microsoft.SqlServer.Types.SqlGeography.STPointFromText(SqlChars pointTaggedText, Int32 srid)
       InnerException:
4

1 回答 1

1

更换你的线路

var text = string.Format("POINT({0} {1})", lon, lat);

经过

var text = string.Format(System.Globalization.CultureInfo.InvariantCulture, "POINT({0} {1})", lon, lat);

在法语,中 a 用作十进制运算符而不是.

于 2014-10-17T22:01:01.590 回答