Maptitude GISDK Help |
This example opens a connection to the GISDK environment, geocodes a street address, and closes the connection to the GISDK environment:
using System;
using System.Collections.Generic;
using System.Text;
using CaliperForm;
///
/// Geocode a street address in the current region.
///
static void Geocode_Street_Address() {
CaliperForm.Connection Conn = new CaliperForm.Connection
{ MappingServer = mapping_product };
Boolean opened = false;
try {
opened = Conn.Open(log_file);
if (opened) {
// You must declare dk as "dynamic" or the compiler will throw an error
dynamic dk = Conn.Gisdk;
// geocode an address
dynamic located_coord = null;
string street_layer_db = null;
dynamic finder = dk.CreateObject("Data.Finder");
finder.SetRegion();
string region_name = finder.GetRegionName();
// Change the address to be in the current region
var args = new OptionsArray();
args["address"] = "200 Beacon Street";
args["city"] = "Boston MA";
args["silent"] = true;
Dictionary<String, Object> result =
Cast.ToDictionary(finder.Find("ADDRESS", args));
// If Success:
// result = {"Coord": coord object, ...}
// If Failure:
// result = {"Error": true, "Message": error message }
if (result != null) {
foreach (string key in result.Keys) {
Console.Out.WriteLine(key + " = " +
Convert.ToString(result[key]));
}
var coord = result["Coord"] as dynamic;
if (coord != null) {
// Success: convert output lat,lon to doubles
double lon = ((double)coord.Lon) / 1000000;
double lat = ((double)coord.Lat) / 1000000;
located_coord = coord;
street_layer_db = result["StreetLayer"] as string;
Console.Out.WriteLine("Address: " + result["Address"] as string + ",
Location: " + lat + "," + lon);
} else {
// Failure, report error message
var has_errors = result["Error"];
var error_message = result["Message"] as string;
Console.Out.WriteLine("Error: " + has_errors as string +
", Message: " + error_message);
}
}
Console.Out.WriteLine();
Conn.Close();
}
} catch (System.Exception error) {
Console.Out.WriteLine(error.Message);
}
}
For more information, see:
Getting Started with CaliperForm
Using the CaliperForm.Connection Class
Using the GISDK Extension Engine In-Process API
See also these specific C# examples for:
©2025 Caliper Corporation | www.caliper.com |