//Add MapPoint namespace using MapPoint; 引入命名空間之后,使用起MapPoint類型就非常方便了。
下一步是創建一個MapPoint 2004的應用對象:
//Define an application instance ApplicationClass app = null; //Create an application class instance app = new ApplicationClass(); MapPoint 2004應用實例(application instance)提供了一個活動的地圖實例來完成面向地圖定位的人物,這個例子里我將使用這個實例來查找一個地址。
//Now get the location FindResults frs = app.ActiveMap.FindAddressResults(" ", " ", string.Empty, "WA", "", null); 你可能已經注重到了,FindAddressResults方法返回的FindResults是一個查詢到的地點的集合,有兩種方法可以從FindResults實例中獲取地點的列表:
//Get an enumerator IEnumerator ienum = frs.GetEnumerator(); //Loop through the enumerator while(ienum.MoveNext()) { Location loc = ienum.Current as Location; if(loc != null) { //process the location string s = loc.StreetAddress.Value; } } 2. 使用get/set訪問方法來用索引獲得地點。這個方法在你需要獲得某個非凡項但又不想循環整個列表時比較有用。如查找第一個相符合的記錄:
//Define an index object index = 1; //Access the location item using the accessor method location = frs.get_Item(ref index) as Location; 這里必須使用get_Item和set_Item方法進行按照索引對記錄進行的操作。
//Define a missing value type object missing = System.Reflection.Missing.Value; //Use the missing type for optional parameters that are not needed DataMap mydatamap = mydataset.DisplayDataMap(GeoDataMapType.geoDataMapTypeShadedArea, field, GeoShowDataBy.geoShowByRegion1, GeoCombineDataBy.geoCombineByDefault, GeoDataRangeType.geoRangeTypeDiscreteLogRanges, GeoDataRangeOrder.geoRangeOrderDefault, 15, 3, missing, missing, missing, missing, missing); 結束語