2

I am trying to get the distance between 2 points using the Longitude and Latitude in c# now i stumbled into some good codes and using them in my code i am getting this as an exception error :

System.Net.WebException: 'Request Not Authorized or Over QueryLimit'

My code is looking thus :

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();
        }
    }
}

Does it look like i am missing something? was made to understand that using Googlemaps.Locationservice is free so i should not be expecting this error...

George
  • 21
  • 1
  • 2
  • I am not a Geo expert but found this StackOverflow link which might be helpful --> https://stackoverflow.com/questions/14014074/google-maps-api-over-query-limit-per-second-limit . Additionally, it appears that the exception you are getting relates to hitting against the service in too short a period which is also mentioned in the Stack link. Cheers! – JavaJd May 10 '19 at 09:37
  • I'm wondering if you use an API key? Please note that API key is required in Google maps platform and without it you will get Unauthorized error messages. – xomena May 11 '19 at 18:03

1 Answers1

0

There are few possible reasons for having unauthorized or over query limit error:

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

If above solutions didn't work or are already done on your end, kindly file a support case via https://console.cloud.google.com/google/maps-apis/support in order to open personalized communication channel as this will need further investigation to address the issue properly.

Shawn Domingo
  • 1,371
  • 1
  • 11
  • 16