PowerTools InputMan for ASP.NET 8.0J
GetCity メソッド (GcAddress)
使用例 

都道府県コードを示す2桁の数字文字列(String 型)
指定した都道府県にあるすべての市区町村の情報を取得します。
構文

パラメータ

prefectureJISCode
都道府県コードを示す2桁の数字文字列(String 型)

戻り値の型

指定した都道府県にあるすべての市区町村の情報を含むRegionInfoオブジェクトのコレクション
解説
返されたRegionInfoオブジェクト内のRegionInfo.Codeプロパティの値は、市区町村コードを示す5桁の数字文字列になります。検索が失敗した場合は空のコレクションが返されます。
使用例
次のサンプルコードは「宮城県仙台市泉区」の郵便番号を取得する方法を示します。
Imports GrapeCity.Web.Input.IMExtenders;

Public Sub HierarchicalAddressSearching()
    ' GcAddressクラスのインスタンスを作成します。
    Dim GcAddress1 As New GcAddress()

    Dim selectedPrefecture As RegionInfo = Nothing
    Dim selectedCity As RegionInfo = Nothing
    Dim selectedTown As RegionInfo = Nothing

    ' すべての都道府県を取得します。
    Dim prefectures As IEnumerable(Of RegionInfo) = GcAddress1.GetPrefecture()
    
    ' 宮城県の地域情報を検索します。
    For Each prefecture As RegionInfo In prefectures
        If prefecture.Name = "宮城県" Then
            selectedPrefecture = prefecture
            Exit For
        End If
    Next

    If selectedPrefecture Is Nothing Then
        Return
    End If

    ' 宮城県の市区町村の情報を取得します。
    Dim cities As IEnumerable(Of RegionInfo) = GcAddress1.GetCity(selectedPrefecture.Code)
    ' "仙台市泉区"の地域情報を検索します。
    For Each city As RegionInfo In cities
        If city.Name = "仙台市泉区" Then
            selectedCity = city
            Exit For
        End If
    Next

    If selectedCity Is Nothing Then
        Return
    End If
    
    ' 宮城県仙台市泉区の町域の情報を取得します。
    Dim towns As IEnumerable(Of RegionInfo) = GcAddress1.GetTown(selectedCity.Code)
    
    ' "紫山"の地域情報を検索し、郵便番号を表示します。
    For Each town As RegionInfo In towns
        If town.Name = "紫山" Then
            System.Diagnostics.Debug.WriteLine("郵便番号:" + town.Code)
            Exit For
        End If
    Next
End Sub
using GrapeCity.Web.Input.IMExtenders

public void HierarchicalAddressSearching()
{
    // GcAddressクラスのインスタンスを作成します。
    GcAddress GcAddress1 = new GcAddress();

    RegionInfo selectedPrefecture = null;
    RegionInfo selectedCity = null;
    RegionInfo selectedTown = null;

    // すべての都道府県を取得します。
    IEnumerable<RegionInfo> prefectures = GcAddress1.GetPrefecture();

    // 宮城県の地域情報を検索します。
    foreach (var prefecture in prefectures)
    {
        
        if (prefecture.Name == "宮城県")
        {
            selectedPrefecture = prefecture;
            break;
        }
    }
    // 宮城県の市区町村の情報を取得します。
    IEnumerable<RegionInfo> cities = GcAddress1.GetCity(selectedPrefecture.Code);

    // "仙台市泉区"の地域情報を検索します。
    foreach (var city in cities)
    {
        if (city.Name == "仙台市泉区")
        {
            selectedCity = city;
            break;
        }
    }

    if (selectedCity == null)
    {
        return;
    }

    // 宮城県仙台市泉区の町域の情報を取得します。
    IEnumerable<RegionInfo> towns = GcAddress1.GetTown(selectedCity.Code);
    
    // "紫山"の地域情報を検索し、郵便番号を表示します。
    foreach (var town in towns)
    {
        if ( town.Name == "紫山")
        {
            selectedTown = town;
            System.Diagnostics.Debug.WriteLine("郵便番号:" + town.Code);
            break;
        }
    }
}
参照

GcAddress クラス
GcAddress メンバ

 

 


© 2005-2015 GrapeCity inc. All rights reserved.