使用GoogleMaps.LocationServices在C#中获取经纬度时遇403错误求助
解决GoogleMaps.LocationServices调用403 (Forbidden)错误
错误原因:Google地理编码API目前强制要求使用API密钥发起请求,你的代码未提供合法密钥,因此被服务器拒绝访问,返回403状态码。
修复步骤:
- 在Google Cloud平台创建API密钥,并启用Geocoding API服务。
- 修改代码,初始化
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; - 确认API密钥已配置正确权限,且未超出免费配额(若使用免费额度)。
额外提示:如果API密钥设置了IP限制,需保证运行代码的设备IP在允许列表内,否则仍会触发403错误。
内容的提问来源于stack exchange,提问作者generic
相关产品推荐
相关产品推荐

