我正在尝试使用 C# 中的经度和纬度来获取两点之间的距离,现在我无意中发现了一些很好的代码并在我的代码中使用它们,我将其作为异常错误获取:
System.Net.WebException: 'Request Not Authorized or Over QueryLimit'
我的代码是这样的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GoogleMaps.LocationServices;
using System.Device.Location;
namespace DistanceCalcConsole
{
class Program
{
static void Main(string[] args)
{
getDistancebetween2Points();
}
private static void getDistancebetween2Points()
{
var originAddress = "Lagos, Nigeria";
var locationService = new GoogleLocationService();
var point = locationService.GetLatLongFromAddress(originAddress);
var latitude1 = point.Latitude;
var longitude1 = point.Longitude;
var destinationAddress = "Ibadan, Nigeria";
var locationService2 = new GoogleLocationService();
var point2 = locationService2.GetLatLongFromAddress(destinationAddress);
var latitude2 = point.Latitude;
var longitude2 = point.Longitude;
var locA = new GeoCoordinate(latitude1, longitude1);
var locB = new GeoCoordinate(latitude2, longitude2);
double distance = locA.GetDistanceTo(locB);
double finalDistance = distance / 1000;
Console.Write(finalDistance +" Kilometers");
Console.Read();
}
}
}
我是不是漏掉了什么?被告知使用 Googlemaps.Locationservice 是免费的,所以我不应该期待这个错误...
最佳答案
出现未经授权或超过查询限制错误的可能原因很少:
如果上述解决方案不起作用或您已经完成,请通过 https://console.cloud.google.com/google/maps-apis/support 提交支持案例为了打开个性化的沟通 channel ,因为这需要进一步调查以妥善解决问题。
关于c# - 获取两点之间的距离返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56074579/