【问题标题】:DbGeography.PointFromText() throws 'Latitude values must be between -90 and 90 degrees' for JapanDbGeography.PointFromText() 为日本抛出“纬度值必须在 -90 到 90 度之间”
【发布时间】:2026-01-08 16:20:07
【问题描述】:

Google 告诉我日本的纬度/经度值为 (36,138),但 .NET 抛出错误

24201: Latitude values must be between -90 and 90 degrees.

有什么想法吗?

【问题讨论】:

    标签: .net geolocation


    【解决方案1】:

    我遇到了和你一样的问题,我使用的是DbGeography.PointFromText("Point(lat lng)"),而 lat & lng 参数是相反的。完整的答案是这样的:

    // From Google, Japan's latitude: 36; longitude: 138
    var lat = 36;
    var lng = 138;
    var location = DbGeography.PointFromText($"Point({lng} {lat})");
    

    【讨论】:

    • 此链接不再有效。您能否将链接中的任何内容放在答案中?
    • 当我尝试实现相同的解决方案时,我做不到,因为 PointFromText 有 2 个参数。公共静态 System.Data.Spatial.DbGeography PointFromText (string pointWellKnownText, int coordinateSystemId);有什么想法吗?
    • 我有这个解决方案,但它不起作用.. if (geoLocation.Longitude.HasValue && geoLocation.Latitude.HasValue) { var point = string.Format(CultureInfo.InvariantCulture.NumberFormat, " POINT({0} {1})", geoLocation.Longitude, geoLocation.Latitude);返回 DbGeography.PointFromText(point, 4326); }