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

使用GoogleMaps.LocationServices在C#中获取经纬度时遇403错误求助

解决GoogleMaps.LocationServices调用403 (Forbidden)错误
  • 错误原因:Google地理编码API目前强制要求使用API密钥发起请求,你的代码未提供合法密钥,因此被服务器拒绝访问,返回403状态码。

  • 修复步骤:

    1. 在Google Cloud平台创建API密钥,并启用Geocoding API服务。
    2. 修改代码,初始化GoogleLocationService时传入你的API密钥:
      using GoogleMaps.LocationServices;
      
      var address = "Dallas, Texas";
      // 替换为你的Google API密钥
      string apiKey = "你的API密钥";
      var locationService = new GoogleLocationService(apiKey);
      var point = locationService.GetLatLongFromAddress(address);
      var latitude = point.Latitude;
      var longitude = point.Longitude;
      
    3. 确认API密钥已配置正确权限,且未超出免费配额(若使用免费额度)。
  • 额外提示:如果API密钥设置了IP限制,需保证运行代码的设备IP在允许列表内,否则仍会触发403错误。

内容的提问来源于stack exchange,提问作者generic

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 06:35:27