generic
generic

Reputation: 301

Error Using GoogleMaps.LocationServices to Find Latitude and Longitude in C#

I am looking for advice on how to get the latitude and longitude of an address using C#. I do not know how to interpret the error message I receive.

Here is my code:

using GoogleMaps.LocationServices;

var address = "Dallas, Texas";
var locationService = new GoogleLocationService();
var point = locationService.GetLatLongFromAddress(address);
var latitude = point.Latitude;
var longitude = point.Longitude;

Here is the error:

Exception Unhandled: System.Net.Http.HttpRequestException: 'Response status code does not indicate success: 403 (Forbidden).'

I get it on line 5, var point = locationService.GetLatLongFromAddress(address);

For your reference, this is the GoogleMaps.LocationServices assembly.

Thank you so much for your help.

Upvotes: 0

Views: 849

Answers (1)

Nora Söderlund
Nora Söderlund

Reputation: 1191

You're not identifying your API key in your location service constructor...so your request is forbidden.

var locationService = new GoogleLocationService(apiKey: "YOUR_API_KEY");

See https://github.com/sethwebster/GoogleMaps.LocationServices and https://developers.google.com/maps/documentation/javascript/get-api-key

Upvotes: 0

Related Questions