User Tools

Site Tools


map_suite_geocoder_quick_start_guide

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
map_suite_geocoder_quick_start_guide [2015/09/07 10:13]
admin
map_suite_geocoder_quick_start_guide [2017/03/17 05:15] (current)
tgwikiupdate
Line 1: Line 1:
 ====== Map Suite Geocoder Quick Start Guide ====== ====== Map Suite Geocoder Quick Start Guide ======
 +
 +{{section>​upgrade_map_suite_to_10.0}}
  
 <div msgbox> <div msgbox>
Line 20: Line 22:
 While the Map Suite Geocoder component takes care of the business of geocoding and reverse geocoding data, in order to display it on an interactive map you need to use a control like Map Suite Desktop Edition. While the Map Suite Geocoder component takes care of the business of geocoding and reverse geocoding data, in order to display it on an interactive map you need to use a control like Map Suite Desktop Edition.
  
-If you installed the ThinkGeo Product Center in the default location, your Map Suite Geocoder 9.0 assemblies will be located in <kbd>C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite Geocoder</kbd>.+If you installed the ThinkGeo Product Center in the default location, your Map Suite Geocoder 9.0 assemblies will be located in //C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite Geocoder//.
 ===== Download the Sample ===== ===== Download the Sample =====
-{{Filelink}}[[:File:​HelloWorld Geocoder.zip|Download Sample Code From This Exercise]] //(16.2 MB)//+<faicon fa fa-download> ​{{https://github.com/​ThinkGeo/​GeocodingSample-ForWinForms|Download Sample Code From GitHub}} ​
  
 ===== Setting up the Environment ===== ===== Setting up the Environment =====
 Let's start with a new Windows Forms project in Microsoft Visual Studio (2012 or newer) and call it "​HelloWorld"​ (see Figure 1). We can create the project with .NET Framework 4.0 or 4.5. Let's start with a new Windows Forms project in Microsoft Visual Studio (2012 or newer) and call it "​HelloWorld"​ (see Figure 1). We can create the project with .NET Framework 4.0 or 4.5.
  
-{{Figure|QSG_Routing_Img001.png|Figure 1. Creating a new project in Microsoft Visual Studio.}}+{{geocoder:QSG_Routing_Img001.png}} 
 +\\ 
 +//Figure 1. Creating a new project in Microsoft Visual Studio.//
  
 The project "​HelloWorld"​ is created in a new solution that is also called "​HelloWorld"​. The wizard creates a single Windows Form. The project "​HelloWorld"​ is created in a new solution that is also called "​HelloWorld"​. The wizard creates a single Windows Form.
Line 39: Line 43:
 Hover on the Toolbox and right click anywhere on the list of controls. You will get a pop-up menu. Select "​Choose items..."​ Hover on the Toolbox and right click anywhere on the list of controls. You will get a pop-up menu. Select "​Choose items..."​
  
-{{Figure|QSG_Routing_Img02.png}}+{{geocoder:QSG_Routing_Img02.png}}
  
-**2.** The Choose Toolbox Items dialogue will appear. You will need to select the ".NET Framework Components"​ tab and then click the "​Browse..."​ button. Finally, navigate to the <kbd>C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite Geocoder\Current Version\Managed Assemblies</kbd> ​folder and select the "​DesktopEdition.dll"​ file.+**2.** The Choose Toolbox Items dialogue will appear. You will need to select the ".NET Framework Components"​ tab and then click the "​Browse..."​ button. Finally, navigate to the //C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite Geocoder\Current Version\Managed Assemblies/folder and select the "​DesktopEdition.dll"​ file.
  
-{{Figure|QSG_Routing_Img03.png}}+{{geocoder:QSG_Routing_Img03.png}}
  
 **3.** You should now have the Map control available in your Toolbox as shown in the following figure. **3.** You should now have the Map control available in your Toolbox as shown in the following figure.
  
-{{Figure|QSG_Geocoder_Img04.png|Figure 2. The Map Controls under the Toolbox window.}}+{{geocoder:QSG_Geocoder_Img04.png}} 
 +\\ 
 +//Figure 2. The Map Controls under the Toolbox window.//
  
 Draw the Map control on the form by clicking on the Map control in the Toolbox and then drag and drop (using the left mouse button) to the size your desire. For this sample, you can leave the name of Map control as winformMap1 so our map will display in it. Draw the Map control on the form by clicking on the Map control in the Toolbox and then drag and drop (using the left mouse button) to the size your desire. For this sample, you can leave the name of Map control as winformMap1 so our map will display in it.
  
-**4.** We need to add "​MapSuiteCore.dll"​ to the reference. Right-click the project in Solution Explorer and select "Add Reference...",​ navigate to the <kbd>C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite Geocoder\Current Version\Managed Assemblies</kbd> ​folder and select "​MapSuiteCore.dll"​.+**4.** We need to add "​MapSuiteCore.dll"​ to the reference. Right-click the project in Solution Explorer and select "Add Reference...",​ navigate to the //C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite Geocoder\Current Version\Managed Assemblies/folder and select "​MapSuiteCore.dll"​.
  
 **5.** Add a Textbox, a Button and a ListBox to the form. **5.** Add a Textbox, a Button and a ListBox to the form.
  
-{{Figure|QSG_Geocoder_Img05.png|Figure 3. Your project workspace with form controls in place.}}+{{geocoder:QSG_Geocoder_Img05.png}} 
 +\\ 
 +//Figure 3. Your project workspace with form controls in place.//
  
 ===== Adding Geocoder Reference to the "Hello World" Sample ===== ===== Adding Geocoder Reference to the "Hello World" Sample =====
-Next, we need to add "​MapSuiteGeocoder.dll"​ to the reference. Right-click the project in Solution Explorer and select "Add Reference..."​ Next, navigate to the <kbd>C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite Geocoder\Current Version\Managed Assemblies</kbd> ​folder and select "​MapSuiteGeocoder.dll"​.+Next, we need to add "​MapSuiteGeocoder.dll"​ to the reference. Right-click the project in Solution Explorer and select "Add Reference..."​ Next, navigate to the //C:\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite Geocoder\Current Version\Managed Assemblies/folder and select "​MapSuiteGeocoder.dll"​.
  
-{{Figure|QSG_Geocoder_Img06.png}}+{{geocoder:QSG_Geocoder_Img06.png}}
  
 Now that we have our "​MapSuiteGeocoder.dll"​ referenced and necessary controls added, we are ready to add the code. Now that we have our "​MapSuiteGeocoder.dll"​ referenced and necessary controls added, we are ready to add the code.
Line 79: Line 87:
 In creating our "Hello World" sample, our first step is to set references to the MapSuiteGeocoder workspace at the very top of our code. Setting a reference to the MapSuiteGeocoder workspace can be done in the "​code-behind"​ of the Form by selecting the Form and pressing the F7 function key. To display the Geocoder results on the map with the MapSuite Desktop Edition, we also need four additional references. You can set all of these references like this: In creating our "Hello World" sample, our first step is to set references to the MapSuiteGeocoder workspace at the very top of our code. Setting a reference to the MapSuiteGeocoder workspace can be done in the "​code-behind"​ of the Form by selecting the Form and pressing the F7 function key. To display the Geocoder results on the map with the MapSuite Desktop Edition, we also need four additional references. You can set all of these references like this:
  
-<source lang="csharp">+<code csharp>
 using ThinkGeo.MapSuite.MapSuiteGeocoder;​ using ThinkGeo.MapSuite.MapSuiteGeocoder;​
 using ThinkGeo.MapSuite.DesktopEdition;​ using ThinkGeo.MapSuite.DesktopEdition;​
 using ThinkGeo.MapSuite.Core;​ using ThinkGeo.MapSuite.Core;​
 using System.Collections.ObjectModel;​ using System.Collections.ObjectModel;​
-</source>+</code>
  
 Before we start looking at the Geocoder code, we need to add some code to display the map. We will add this code in the Form Load event handler as follows: Before we start looking at the Geocoder code, we need to add some code to display the map. We will add this code in the Form Load event handler as follows:
  
-<source lang='csharp'>+<code csharp>
 private void Form1_Load(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e)
     {     {
-        ​<​nowiki>​//</​nowiki> ​Setting up the map unit and set the Chicago extent+        // Setting up the map unit and set the Chicago extent
         winformsMap1.MapUnit = GeographyUnit.DecimalDegree;​         winformsMap1.MapUnit = GeographyUnit.DecimalDegree;​
         winformsMap1.CurrentExtent = new RectangleShape(-125,​ 50, -66, 23);         winformsMap1.CurrentExtent = new RectangleShape(-125,​ 50, -66, 23);
  
-        ​<​nowiki>​//</​nowiki> ​Create the overlay and add it to the map+        // Create the overlay and add it to the map
         LayerOverlay mainOverlay = new LayerOverlay();​         LayerOverlay mainOverlay = new LayerOverlay();​
         winformsMap1.Overlays.Add("​mainOverlay",​ mainOverlay);​         winformsMap1.Overlays.Add("​mainOverlay",​ mainOverlay);​
  
-        ​<​nowiki>​//</​nowiki> ​Setup the World Map Kit WMS Overlay+        // Setup the World Map Kit WMS Overlay
         WorldMapKitWmsDesktopOverlay worldMapKitOverlay = new WorldMapKitWmsDesktopOverlay();​         WorldMapKitWmsDesktopOverlay worldMapKitOverlay = new WorldMapKitWmsDesktopOverlay();​
         winformsMap1.Overlays.Add("​WorldMapKitOverlay",​ worldMapKitOverlay);​         winformsMap1.Overlays.Add("​WorldMapKitOverlay",​ worldMapKitOverlay);​
  
-        ​<​nowiki>​//</​nowiki> ​Setup the marker overlay and add it to the map            ​+        // Setup the marker overlay and add it to the map            ​
         LayerOverlay markerOverlay = new LayerOverlay();​         LayerOverlay markerOverlay = new LayerOverlay();​
         winformsMap1.Overlays.Add("​MarkerOverlay",​ markerOverlay);​         winformsMap1.Overlays.Add("​MarkerOverlay",​ markerOverlay);​
  
-        ​<​nowiki>​//</​nowiki> ​Setup the marker layer+        // Setup the marker layer
         InMemoryFeatureLayer markerLayer = new InMemoryFeatureLayer();​         InMemoryFeatureLayer markerLayer = new InMemoryFeatureLayer();​
         markerLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;​         markerLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;​
Line 115: Line 123:
         winformsMap1.Refresh();​         winformsMap1.Refresh();​
     }     }
-</source>+</code>
  
 Now let's look at some sample code that will bring these concepts to fruition. In this code, we'll accomplish the following: Now let's look at some sample code that will bring these concepts to fruition. In this code, we'll accomplish the following:
  
-#Add a click event handler for the Button.  +  - Add a click event handler for the Button.  
-#Create a <​code>​UsaGeocoder</​code> ​object and pass the index data path to the constructor.  +  ​- ​Create a ''​UsaGeocoder'' ​object and pass the index data path to the constructor.  
-#Call the <​code>​Open</​code> ​method.  +  ​- ​Call the ''​Open'' ​method.  
-#Call the <​code>​Match</​code> ​method to get the <​code>​MatchResult</​code> ​object.  +  ​- ​Call the ''​Match'' ​method to get the ''​MatchResult'' ​object.  
-#Finally, call the <​code>​Close</​code> ​method to close. ​+  ​- ​Finally, call the ''​Close'' ​method to close. ​
  
-<source lang="csharp"+<code csharp>​ 
-<​nowiki>​//</​nowiki> ​Get the path to the data files and create the Geocoder+// Get the path to the data files and create the Geocoder
     UsaGeocoder usaGeocoder = new UsaGeocoder(@"​C:​\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite GeoCoder\Sample Templates\AddressLocator_Desktop\AddressLocator_Desktop\App_Data",​ MatchMode.FuzzyMatch);​     UsaGeocoder usaGeocoder = new UsaGeocoder(@"​C:​\Program Files (x86)\ThinkGeo\Map Suite 9.0\Map Suite GeoCoder\Sample Templates\AddressLocator_Desktop\AddressLocator_Desktop\App_Data",​ MatchMode.FuzzyMatch);​
  
-    ​<​nowiki>​//</​nowiki> ​Open the geocoder, get any matches and close it+    // Open the geocoder, get any matches and close it
     Collection<​GeocoderMatch>​ geocoderMatches;​     Collection<​GeocoderMatch>​ geocoderMatches;​
     try     try
Line 140: Line 148:
         usaGeocoder.Close();​         usaGeocoder.Close();​
     }      } 
-</source>+</code>
  
-You can get results in detail by looping through ​<​code>​geocoderMatches</​code> ​and displaying them on the map.+You can get results in detail by looping through ​''​geocoderMatches'' ​and displaying them on the map.
  
-<source lang="csharp">+<code csharp>
 InMemoryFeatureLayer markerLayer = winformsMap1.FindFeatureLayer("​MarkerLayer"​) as InMemoryFeatureLayer;​ InMemoryFeatureLayer markerLayer = winformsMap1.FindFeatureLayer("​MarkerLayer"​) as InMemoryFeatureLayer;​
     if (geocoderMatches.Count > 0)     if (geocoderMatches.Count > 0)
Line 165: Line 173:
         winformsMap1.Refresh();​         winformsMap1.Refresh();​
     }     }
-</​source>​ +</​code>​
- +
-Now, build and run the sample. ​ Because our sample data set only contains street data for Chicago, IL, to perform a test you will need to enter an address in Chicago and then click the button to locate it.  Once you do, Map Suite Geocoder will return a result on your map, similar to the following screenshot:​ +
- +
-{{Figure|QSG_Geocoder_Img07b.png|Figure 4. Your first geocoding application is up and running.}} +
- +
-===== Summary ===== +
-You now know the basics of using Map Suite Geocoder and are able to get started adding functionality to your own applications. Let's recap what we have learned about the object relationships and how the various parts of the Map Suite Geocoder work together: +
- +
-#There is a Open-Match-Close pattern in the Geocoder object;  +
-#The Geocoder returns a collection of <​code>​GeocoderMatch</​code>​ objects, each of which represents one matched result; +
-#A <​code>​GeocoderMatch</​code> ​object contains a key-value collection. +
- +
-[[Category:​Map Suite Geocoder]] [[Category:​Web GIS]] [[Category:​Desktop GIS]] [[Category:​GIS]] [[Category:​.NET]]+
  
 +Now, build and run the sample. ​ Because our sample data set only contains street data for Chicago, IL, to perform a test you will need to enter an address in
map_suite_geocoder_quick_start_guide.1441620788.txt.gz · Last modified: 2015/09/07 10:13 by admin