繁体   English   中英

在 C# 中使用 GoogleMaps.LocationServices 查找纬度和经度时出错

[英]Error Using GoogleMaps.LocationServices to Find Latitude and Longitude in C#

我正在寻找有关如何使用 C# 获取地址的纬度和经度的建议。 我不知道如何解释我收到的错误消息。

这是我的代码:

using GoogleMaps.LocationServices;

var address = "Dallas, Texas";
var locationService = new GoogleLocationService();
var point = locationService.GetLatLongFromAddress(address);
var latitude = point.Latitude;
var longitude = point.Longitude;

这是错误:

未处理的异常:System.Net.Http.HttpRequestException:“响应状态代码不表示成功:403(禁止)。”

我在第 5 行得到它, var point = locationService.GetLatLongFromAddress(address);

供您参考,这是 GoogleMaps.LocationServices 程序集

非常感谢你的帮助。

您没有在您的位置服务构造函数中识别您的 API 密钥……因此您的请求被禁止。

var locationService = new GoogleLocationService(apiKey: "YOUR_API_KEY");

请参阅https://github.com/sethwebster/GoogleMaps.LocationServiceshttps://developers.google.com/maps/documentation/javascript/get-api-key

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM