Search code examples
c#.netopenstreetmapreverse-geocodingmapquest

Mapquest: This key is not authorized for this service


I am trying to use Geocoding.net to reverse geocode my latitude and longitude to a formatted address. I want a address from MapQuest and not from other providers like Yahoo, google and bing. This is my Code:

    try
    {
        IGeocoder geocoder = new MapQuestGeocoder("Fmjtd%7Cluu82q6***********");
        var addresses = geocoder.ReverseGeocode(latitude, longitude);
        return ("Formatted address :  " + addresses.First().FormattedAddress);
    }
    catch (Exception exception)
    {
        return exception.Message;
    }

This code catches an exception and thorws this error "This key is not authorized for this service."

I know that this error occurs when I try to hit the Enterprise API of Geocoder i.e http://www.mapquestapi.com/geocoding/v1/reverse?key=*******************

For free and open source usage, I should hit this API:

http://open.mapquestapi.com/geocoding/v1/address?key=YOUR-KEY-HERE

How can I do this? Is there any option of passing the POST URL in the constructor itself? Or any other way?


Solution

  • Scanning over the open-source code of Geocoding.net, it looks like you just need to set the "UseOSM" property of your geocoder object to true:

    geocoder.UseOSM = true;