2016-05-13 5 views
2

IPアドレスからIipLocationオブジェクトを取得するメソッドを使用しています。 RegionRegionNameCountryCodeCityPostal CodeLatitudeLongitude地理的位置 - 州と郡を取得するには? (または、郵便番号から州と郡を取得する方法)C#

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

IipLocationオブジェクトは、次の特性をもつ:この場所のオブジェクトを返すコードです。しかし、私は州と郡が必要です。私が持っている情報から州と郡を取得するにはどうすればいいですか?

+0

私は少し混乱しています。 'GetMaxMindIpLocation()'はどこから来ますか? [MaxMindの公式API](https://github.com/maxmind/GeoIP2-dotnet#city-database)には、探しているすべてのデータがあります。 –

答えて

関連する問題