简体   繁体   English

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

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

I am looking for advice on how to get the latitude and longitude of an address using C#.我正在寻找有关如何使用 C# 获取地址的纬度和经度的建议。 I do not know how to interpret the error message I receive.我不知道如何解释我收到的错误消息。

Here is my code:这是我的代码:

using GoogleMaps.LocationServices;

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

Here is the error:这是错误:

Exception Unhandled: System.Net.Http.HttpRequestException: 'Response status code does not indicate success: 403 (Forbidden).'未处理的异常:System.Net.Http.HttpRequestException:“响应状态代码不表示成功:403(禁止)。”

I get it on line 5, var point = locationService.GetLatLongFromAddress(address);我在第 5 行得到它, var point = locationService.GetLatLongFromAddress(address);

For your reference, this is the GoogleMaps.LocationServices assembly .供您参考,这是 GoogleMaps.LocationServices 程序集

Thank you so much for your help.非常感谢你的帮助。

You're not identifying your API key in your location service constructor...so your request is forbidden.您没有在您的位置服务构造函数中识别您的 API 密钥……因此您的请求被禁止。

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

See https://github.com/sethwebster/GoogleMaps.LocationServices and https://developers.google.com/maps/documentation/javascript/get-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