使用GoogleMaps出错.在c#中查找经纬度的LocationServices



我正在寻找如何使用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: 'Response status code does not indicate success: 403 (Forbidden).'

在第5行,var point = locationService.GetLatLongFromAddress(address);

供您参考,这是GoogleMaps。LocationServices组装。

非常感谢你的帮助。

你没有在你的位置服务构造函数中识别你的API密钥…所以你的请求被禁止了。

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

参见https://github.com/sethwebster/GoogleMaps.LocationServices和https://developers.google.com/maps/documentation/javascript/get-api-key

最新更新