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

标签 c# google-maps

我正在尝试使用 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/

相关文章:

c# - 在自己的类中动态设置属性

C# 句柄数

c# - 从 Excel 导入到 MVC3 应用程序的最快方法

c# - 在内存中将 BMP 转换为 PNG,以便在 .Net 中粘贴剪贴板

google-maps - 如何为谷歌地图标记添加背景图片?

c# - 为所有 View 定义一个部分

css - 谷歌地图自动完成,修复输入

javascript - 在 Google 散点图点单击上显示 Google map 信息窗口

ios - 适用于 IOS 的 Google Maps SDK - 标记始终居中

javascript - ASP.NET MVC 3 和 Google map API