获取2点之间的距离会返回错误

时间:2019-05-10 09:25:37

标签: c# google-maps

我正在尝试使用C#中的经度和纬度来获取2点之间的距离,现在我偶然发现了一些好的代码,并在我的代码中使用了它们,这是我得到的异常错误:

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 个答案:

答案 0 :(得分:1)

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

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

如果上述解决方案无效或已经解决,请通过https://console.cloud.google.com/google/maps-apis/support提交支持案例,以打开个性化的沟通渠道,因为这需要进一步调查以正确解决问题。

>