2

I'm using a method to get an IipLocation object from an IP address. This is the code that returns the Location object:

public IIpLocation GetIpLocation(IPAddress ipAddress)
{
    ipAddress.CheckNull("ipAddress");

    IIpLocation ipLocation = null;
    try
    {
        //Try to look up the location using MaxMind.
        Location location = GetMaxMindIpLocation(ipAddress);

        //If the postal code is not present, then try to look it up with GeoNames.
        if (location != null && (location.PostalCode == null || location.PostalCode.Equals("")))
        {
            location.PostalCode = GetPostalCodeFromGeoNames(location);
        }

        if (location != null)
        {
            ipLocation = new GeoIpLocation(location);
        }
    }
    catch (NullReferenceException)
    {
        Log.ErrorFormat(Resources.log_maxMindLookupFailed, ipAddress);
    }

    return ipLocation;
}

The IipLocation object has the following properties: Region, RegionName, CountryCode, City, Postal Code, Latitude, Longitude. However, I need the State and County. How can I get the state and county from the information that I have?

Erica Stockwell-Alpert
  • 4,624
  • 10
  • 63
  • 130
  • I am a bit confused. Where is `GetMaxMindIpLocation()` coming from? [MaxMind's official API](https://github.com/maxmind/GeoIP2-dotnet#city-database) has all of the data you are looking for. – Greg Oschwald May 13 '16 at 22:47

1 Answers1

2

Use Census Block Conversions API accomplish this.

ex:

http://data.fcc.gov/api/block/find?format=json&latitude=28.35975&longitude=-81.421988&showall=true

sammarcow
  • 2,736
  • 2
  • 28
  • 56