You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为地理坐标点生成谷歌地图链接?代码失效求助

问题排查与解决
  • 核心错误:坐标顺序颠倒
    NetTopologySuite中Coordinate.X代表经度,Coordinate.Y代表纬度,但谷歌地图的定位链接格式要求是@纬度,经度,缩放级别z,你的代码把经度(X)放在了纬度(Y)的前面,导致定位到错误位置。

  • 修正后的代码

public NetTopologySuite.Geometries.Geometry? GeoItem { get; set; }
public string? GoogleMapsLink {get;set;}
public void Links()
{
    if(this.GeoItem != null)
    {
        // 交换X和Y的顺序:纬度在前,经度在后
        string latitude = this.GeoItem.Coordinate.Y.ToString();
        string longitude = this.GeoItem.Coordinate.X.ToString();
        string googleUrl = $"https://www.google.com/maps/@{latitude},{longitude},17.5z";
        this.GoogleMapsLink = googleUrl;
    }
}
  • 验证示例
    你提供的坐标30.152169(经度) 41.070933(纬度),修正后的链接为https://www.google.com/maps/@41.070933,30.152169,17.5z,这个链接可以正常定位到正确的地理位置。

内容的提问来源于stack exchange,提问作者Arda Şen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 17:15:38