gpt4 book ai didi

c# - 获取两点之间的距离返回错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:42:30 25 4
gpt4 key购买 nike

我正在尝试使用 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 是免费的,所以我不应该期待这个错误...

最佳答案

出现未经授权或超过查询限制错误的可能原因很少:

  1. Billing not enabled
  2. Keyless Implementation
  3. Self-Imposed usage cap

如果上述解决方案不起作用或您已经完成,请通过 https://console.cloud.google.com/google/maps-apis/support 提交支持案例为了打开个性化的沟通 channel ,因为这需要进一步调查以妥善解决问题。

关于c# - 获取两点之间的距离返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56074579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com