国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

微軟地圖MapPoint2004編程簡介(圖)

2019-11-18 11:58:26
字體:
供稿:網(wǎng)友


  假如你還不了解微軟的MapPoint相關(guān)產(chǎn)品和服務(wù),建議去看一下MSDN上的《MapPoint 2004 與 MapPoint Web 服務(wù),該使用哪一個(gè)》這篇文章,這里為了給讀者一個(gè)初步印象,引用其中的一段話。本文介紹的是如何結(jié)合.NET開發(fā)環(huán)境開發(fā)基于MapPoint 2004的應(yīng)用。
  
  MSDN中關(guān)于MapPoint 2004的敘述:
  
  MapPoint 2004 是一個(gè)桌面地圖信息工具,它可以提供奇妙和豐富的用戶體驗(yàn),具有專題圖形、區(qū)域治理、路線優(yōu)化和人口統(tǒng)計(jì)數(shù)據(jù)等功能。所有必要的數(shù)據(jù)都安裝在本地,因此不需要網(wǎng)絡(luò)連接。對(duì)于 MapPoint 2004,您可以方便地使用多種常見格式(Microsoft Excel、Microsoft access、開放數(shù)據(jù)庫連接 (ODBC) 等)導(dǎo)入數(shù)據(jù),并使用專題圖形(如圖 1 所示的餅形圖)以圖形方式顯示這些信息。
  
 微軟地圖MapPoint2004編程簡介(圖)(圖一)

  
MapPoint 2004

  
  使用 MapPoint,您可以采用若干種開發(fā)方式:
  
  ·創(chuàng)建 COM 外接程序以擴(kuò)展 MapPoint 的功能。
  
  ·使用 MapPoint 附帶的 ActiveX 控件將圖形嵌入到您自己的 Microsoft Visual Basic 應(yīng)用程序中。
  
  ·在其他應(yīng)用程序(例如,Microsoft Word 或 Excel)中使用 Microsoft Visual Basic for applications 自動(dòng)實(shí)現(xiàn) MapPoint 和其他應(yīng)用程序之間的連接。
  
  ·使用 Visual Basic(或任何其他與 COM 兼容的編程語言)創(chuàng)建自動(dòng)執(zhí)行 MapPoint 的可執(zhí)行文件或動(dòng)態(tài)鏈接庫 (DLL)。
  
  以上內(nèi)容節(jié)選自MSDN。
  
  正文
  
  簡介
  
  MapPoint 2004給程序員提供了豐富的對(duì)象模型來開發(fā)強(qiáng)大的商業(yè)化的智能地圖定位應(yīng)用。不過它是基于COM的思想設(shè)計(jì)的,所以假如你使用.NET Framework來編寫應(yīng)用程序的話,你必須結(jié)合使用COM的類庫。
  
  本文通過開發(fā)一個(gè)地址查找程序,講解了如何一步步是使用.NET Framework來開發(fā)基于MapPoint 2004的應(yīng)用,同時(shí)也介紹了開發(fā)時(shí)需要注重的一些地方和解決方法。
  
  使用MapPoint2004編程
  
  就像前文所說,你必須結(jié)合使用MapPoint COM庫,才能使用微軟的.NET Framework進(jìn)行編程。假如你使用Visual Studio .NET,你可以在創(chuàng)建新工程之后,選擇PRoject樹型列表項(xiàng)中的Add Reference選項(xiàng)來添加:
  
 微軟地圖MapPoint2004編程簡介(圖)(圖二)

  
MapPoint 2004

  
  當(dāng)看到Add Reference對(duì)話框窗口出現(xiàn)時(shí),選擇COM的Tab頁,并且從列表中選擇Microsoft MapPoint 11.0 Object Library ( )來添加一個(gè)對(duì)MapPoint2004類型庫的引用,如下:
  
微軟地圖MapPoint2004編程簡介(圖)(圖三)

  
MapPoint 2004

  
  下面,開始編寫C#程序,首先需要引進(jìn)MapPoint 2004命名空間:
  
  //Add MapPoint namespace
  using MapPoint;
  
  引入命名空間之后,使用起MapPoint類型就非常方便了。
  
  下一步是創(chuàng)建一個(gè)MapPoint 2004的應(yīng)用對(duì)象:
  
  //Define an application instance
  ApplicationClass app = null;
  //Create an application class instance
  app = new ApplicationClass();
  
  MapPoint 2004應(yīng)用實(shí)例(application instance)提供了一個(gè)活動(dòng)的地圖實(shí)例來完成面向地圖定位的人物,這個(gè)例子里我將使用這個(gè)實(shí)例來查找一個(gè)地址。
  
  //Now get the location
  FindResults frs = app.ActiveMap.FindAddressResults(" ", " ", string.Empty, "WA", "", null);
  
  你可能已經(jīng)注重到了,F(xiàn)indAddressResults方法返回的FindResults是一個(gè)查詢到的地點(diǎn)的集合,有兩種方法可以從FindResults實(shí)例中獲取地點(diǎn)的列表:
  
  1. 獲取一個(gè)enumerator并且枚舉整個(gè)地點(diǎn)的列表。假如你想提供符合條件的地址的列表這樣的方式比較有用。
  
  //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訪問方法來用索引獲得地點(diǎn)。這個(gè)方法在你需要獲得某個(gè)非凡項(xiàng)但又不想循環(huán)整個(gè)列表時(shí)比較有用。如查找第一個(gè)相符合的記錄:
  
  //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方法進(jìn)行按照索引對(duì)記錄進(jìn)行的操作。
  
  最后當(dāng)你做完上述的操作之后,你必須記住要關(guān)閉應(yīng)用程序?qū)ο螅瑏泶_保MapPoint 2004的應(yīng)用程序?qū)嵗粫?huì)保留在內(nèi)存中,可以使用如下代碼:
  
  //Quit the application
  if(app != null)
  app.Quit();
  app = null;
  
  以下代碼完整的列出了一個(gè)根據(jù)上文的方法,查找地址的函數(shù):
  
  //Define an application instance
  ApplicationClass app = null;
  //Define a location instance
  Location location = null;
  //Define a FindResults instance
  FindResults frs = null;
  try
  {
  //Create an application class
  app = new ApplicationClass();
  //Now get the location
  frs = app.ActiveMap.FindAddressResults(" ", " ", string.Empty, "WA", "", null);
  //Check if the find query is sUCcesfull
  if(frs != null && frs.Count > 0)
  {
  object index = 1;
  location = frs.get_Item(ref index) as Location;
  //Male the MapPoint 2004 application visible
  //and go to that location
  app.Visible = true;
  location.GoTo();
  //Do your processing with the location
  MessageBox.Show(location.StreetAddress.Value);
  }
  }
  catch(Exception ex)
  {
  string message = ex.Message;
  }
  finally
  {
  if(app != null)
  {
  try
  {
  app.Quit();
  }
  catch
  {
  //This means your app has already quit!
  }
  finally
  {
  app = null;
  }
  }
  }
  
  需要注重的地方
  
  使用可選參數(shù)的方法進(jìn)行編程
  
  當(dāng)你使用有可選參數(shù)的方法時(shí),假如你沒有傳遞有效的參數(shù),你必須使用缺失類型System.Reflection.Missing.Value。比如DisplayDataMap函數(shù)如下:
  
  DisplayDataMap([DataMapType], [DataField], [ShowDataBy], [CombineDataBy], [DataRangeType], [DataRangeOrder], [ColorScheme], [DataRangeCount], [ArrayOfCustomValues], [ArrayOfCustomNames], [DivideByField], [ArrayOfDataFieldLabels], [ArrayOfPushpinSymbols])
  
  可以看到所有的參數(shù)都是可選參數(shù),這里就必須用到.NET Framework里的缺失類型了。下面的代碼展示了如何使用:
  
  //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);

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 凉山| 桂阳县| 黎平县| 莒南县| 漳州市| 滨州市| 安远县| 综艺| 辽阳市| 阳信县| 安义县| 通江县| 平潭县| 内乡县| 罗城| 越西县| 资溪县| 尚志市| 鄂托克前旗| 郴州市| 叙永县| 闽侯县| 霍城县| 陵水| 松原市| 饶平县| 吴旗县| 抚顺市| 三亚市| 东兴市| 大荔县| 定西市| 永济市| 万全县| 都匀市| 和林格尔县| 涞源县| 海阳市| 胶州市| 安国市| 达拉特旗|