Community of VE/MapPoint Users and Developers
This is a discussion on GeoCode Calc Code & Setting - with question on licencing within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; Question on Licensing: If a company(service Provider) offers web service to another company (client) the following function of the MapPoint ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| GeoCode Calc Code & Setting - with question on licencing Make Sure you have the Mappoint installed locally on the Server. Steps to get add reference to MS Mappoint 1. New Project in Visual Studio.NET 2. Right Click References in Solution Explorer and select Add References 3. Select the COM from the tabs in the Add Reference Pop up 4. Find the Microsoft Mappoint 11.0 Object Library 5. Select that and Click OK Security Setting to use the MapPoint2004 Access Object Model with ASP.NET Web Application: 1. WebConfig file: Fix your authentication properties: <authentication mode="Windows" /> <identity impersonate="true"/> See this link for more information: http://msdn.microsoft.com/library/de...SecNetAP05.asp 2. Component Service Configuration: Click Start, click Run, and then type DCOMCNFG. Select the application that you want to automate. Click Properties to open the property dialog box for this application. Click the Security tab. Verify that Use Default Access Permissions and Use Default Launch Permissions are selected. Click the Identity tab and then select The Interactive User. Component under consideration: Microsoft MapPOint Microsoft MapPoint COntrol 11.0 3. Use this Private App As MapPoint.ApplicationClass instead of Private App As MapPoint.Application App = New MapPoint.Application 4. Make sure ASPNET or NETWORK Service or IUSER have all required execute permission on all require dll such as Interop.Mappoint.dll, c:\windows\system32\msvcp50.dll Code for CensusTract and Lat Long: Imports System.Math Public Class MapPointGeoData Private Map As MapPoint.Map Private App As MapPoint.ApplicationClass Private NewApp As Boolean Private MapStyle As MapPoint.GeoMapStyle Private MapAltitude As String Private Location As MapPoint.Location Private BlockMapStyle As Boolean ' If true, don't active swtich the map style after each find Private Latitute As Double Private Longitute As Double Private CensusTract As String Private StreetAddress As String Private City As String Private State As String Private Zip As String Private Country As String Public WriteOnly Property LockMapStyle() As Boolean Set(ByVal Value As Boolean) If Value And Not BlockMapStyle Then ' If off and turned on, record the current map style BlockMapStyle = True MapStyle = Map.MapStyle MapAltitude = Map.Altitude.ToString Location = Map.Location Map.MapStyle = MapPoint.GeoMapStyle.geoMapStyleData Map.Altitude = "15" ElseIf Not Value And BlockMapStyle Then ' If on and turned off, revert to the old map style BlockMapStyle = False Map.MapStyle = MapStyle Map.Altitude = MapAltitude Location.GoTo() End If End Set End Property Public Sub New() NewApp = False Try App = GetObject(, "MapPoint.Application") NewApp = True Catch ex As System.Exception NewApp = True App = New MapPoint.Application End Try Map = App.ActiveMap BlockMapStyle = False End Sub Public Sub New(ByVal Address As String) NewApp = False Try App = GetObject(, "MapPoint.Application") NewApp = True Catch ex As System.Exception NewApp = True App = New MapPoint.Application End Try Map = App.ActiveMap BlockMapStyle = False SetAddress(Address) End Sub Public Sub New(ByVal StreetAddress As String, ByVal City As String, ByVal State As String, ByVal Zip As String, ByVal Country As String) NewApp = False Try App = GetObject(, "MapPoint.Application") NewApp = True Catch ex As System.Exception NewApp = True App = New MapPoint.Application End Try Map = App.ActiveMap BlockMapStyle = False SetAddress(StreetAddress, City, State, Zip, Country) End Sub Protected Overrides Sub Finalize() Map.Saved = False If NewApp Then App = Nothing MyBase.Finalize() End Sub Public Sub SetAddress(ByVal Street As String, ByVal City As String, ByVal State As String, ByVal Zip As String, ByVal Country As String) Me.StreetAddress = Street Me.City = City Me.State = State Me.Zip = Zip Me.Country = Country End Sub Public Sub SetAddress(ByVal Address As String) If Address.StartsWith("Address not") Then Me.StreetAddress = "1 Microsoft Way" Me.City = " Redmond" Me.State = "WA" Else Dim AddArray As String() = System.Text.RegularExpressions.Regex.Split(Address , ",") Me.StreetAddress = AddArray(0) Me.City = AddArray(1) Dim StateZip As String() = System.Text.RegularExpressions.Regex.Split(AddArra y(2), " ") Me.State = StateZip(0) Me.Zip = StateZip(1) End If End Sub Public Sub SetLocation() 'MsgBox(Me.StreetAddress & ", " & Me.City & ", " & Me.State & ", " & Me.Zip & ", " & Me.Country) Location = Map.FindAddressResults(Me.StreetAddress, Me.City, , , Me.Zip, Me.Country)(1) 'MsgBox(Location.StreetAddress.Value.ToString) FindLatLong(Me.Location) 'MsgBox(Me.Latitute & "x" & Me.Longitute) FindCensusTract(Me.Location) 'MsgBox(Me.CensusTract) End Sub Public Sub SetLocation(ByVal Location As MapPoint.Location) Me.Location = Location 'FindLatLong(Me.Location) CalcPos(Me.Location) FindCensusTract(Me.Location) End Sub Private Sub FindLatLong(ByVal Location As MapPoint.Location) Dim oPush As MapPoint.Pushpin Dim oLoc As MapPoint.Location Dim oLocA As MapPoint.Location Dim Measure As Double = 0.01471 * 750 Dim zLat As Double Dim zLong As Double Dim DistX As Double Dim DistY As Double Dim DistZ As Double Dim PointX As MapPoint.Location Dim PointY As MapPoint.Location Dim myLat = 37.70212 Dim myLong = -97.31775 Dim x zLat = myLat zLong = myLong oLoc = Map.GetLocation(myLat, myLong) oLocA = Location On Error Resume Next x = 0 Do While Measure > 0.00005572 x = x + 1 PointX = Map.GetLocation(zLat + Measure, zLong) PointY = Map.GetLocation(zLat, zLong + Measure) DistX = oLocA.DistanceTo(PointX) DistY = oLocA.DistanceTo(PointY) DistZ = oLocA.DistanceTo(oLoc) If DistX < DistY And DistX < DistZ Then oLoc = Map.GetLocation(zLat + Measure, zLong) zLat = zLat + Measure End If If DistY < DistX And DistY < DistZ Then oLoc = Map.GetLocation(zLat, zLong + Measure) zLong = zLong + Measure End If If DistZ < DistX And DistZ < DistY Then oLoc = Map.GetLocation(zLat - Measure, zLong - Measure) zLat = zLat - Measure zLong = zLong - Measure End If If oLocA.DistanceTo(oLoc) < Measure / 0.01471 Then Measure = Measure / 2 Loop Latitute = zLat Longitute = zLong EndNow: Map.Saved = False End Sub Private Sub FindCensusTract(ByVal Location As MapPoint.Location) Dim Result As String Dim FindResults As MapPoint.FindResults Dim OldMapStyle As MapPoint.GeoMapStyle Dim OldAltitude As String Dim OldLocation As MapPoint.Location With Map If Not BlockMapStyle Then OldMapStyle = .MapStyle ' Not Block, so record current map style OldAltitude = .Altitude.ToString OldLocation = .Location If (OldMapStyle <> MapPoint.GeoMapStyle.geoMapStyleData) Then .MapStyle = MapPoint.GeoMapStyle.geoMapStyleData If (OldAltitude <> "15") Then .Altitude = "15" End If Location.GoTo() FindResults = .ObjectsFromPoint(.LocationToX(Location), .LocationToY(Location)) If FindResults.Count > 0 Then For Each Loc As Object In FindResults If Loc.Name.Trim.Length > 0 Then Result = Loc.Name Exit For End If Next Else Result = "" End If If Not BlockMapStyle Then If (OldMapStyle <> MapPoint.GeoMapStyle.geoMapStyleData) Then .MapStyle = OldMapStyle If (OldAltitude <> "15") Then .Altitude = OldAltitude OldLocation.GoTo() End If End With CensusTract = Result End Sub Public Function GetAddressArray() As ArrayList Dim AddressArray As New ArrayList Dim app As MapPoint.ApplicationClass = Nothing Dim loc As MapPoint.Location = Nothing Dim frs As MapPoint.FindResults = Nothing Try app = New MapPoint.ApplicationClass frs = app.ActiveMap.FindAddressResults(StreetAddress, City, String.Empty, State, Zip, Country) Dim ienum As IEnumerator = frs.GetEnumerator While ienum.MoveNext loc = ienum.Current If (IsDBNull(loc)) Or (loc Is Nothing) Or (loc.StreetAddress Is Nothing) Or (IsDBNull(loc.StreetAddress)) Then AddressArray.Add("Address not Found") Else AddressArray.Add(loc.StreetAddress.Value) End If End While Catch ex As Exception AddressArray.Add(ex.ToString) Finally Try app.Quit() Catch ex As Exception 'This means app has already quit Finally app = Nothing End Try End Try Return AddressArray End Function Public Function GetLatitute() As Double Return Me.Latitute End Function Public Function GetLongitute() As Double Return Me.Longitute End Function Public Function GetCensusTract() As String Return Me.CensusTract End Function Public Function GetZipCode() As String Return Me.Location.StreetAddress.PostalCode.ToString End Function Public Function GetStreet() As String Return Me.Location.StreetAddress.Street.ToString End Function Public Function GetCity() As String Return Me.Location.StreetAddress.City.ToString End Function Public Function GetState() As String Return Me.Location.StreetAddress.Region.ToString End Function Public Function GetAddress() As String With Location.StreetAddress Return .Street & ", " & .City & ", " & .Region & " " & .PostalCode & " " & .Country End With End Function Public Function GetLocation() As MapPoint.Location Return Me.Location.StreetAddress End Function ' Compute latitude and longitude given a location object ' Author: Gilles Kohl ' (gilles@compuserve.com) ' ' This code is copyrighted freeware - use freely, but please leave this ' header intact. Suggestions and comments welcome. Private Function Arccos(ByVal x As Double) As Double If x = 1 Then Arccos = 0 Exit Function End If Arccos = Atan(-x / Sqrt(-x * x + 1)) + 2 * Atan(1) End Function Private Sub CalcPos(ByVal locX As MapPoint.Location) Static locNorthPole As MapPoint.Location Static locSantaCruz As MapPoint.Location ' Center of western hemisphere Static dblHalfEarth As Double ' Half circumference of the earth (as a sphere) Static dblQuarterEarth As Double ' Quarter circumference of the earth (as a sphere) Static Pi As Double ' Check if initialization already done If locNorthPole Is Nothing Then locNorthPole = Map.GetLocation(90, 0) locSantaCruz = Map.GetLocation(0, -90) ' Compute distance between north and south poles == half earth circumference dblHalfEarth = Map.Distance(locNorthPole, Map.GetLocation(-90, 0)) ' Quarter of that is the max distance a point may be away from locSantaCruz and still be in western hemisphere dblQuarterEarth = dblHalfEarth / 2 Pi = 3.14159265358979 End If ' Compute latitude from distance to north pole Latitute = 90 - 180 * Map.Distance(locNorthPole, locX) / dblHalfEarth Dim l As Double Dim d As Double ' Compute great circle distance to locX from point on Greenwich meridian and computed Latitude d = Map.Distance(Map.GetLocation(Latitute, 0), locX) ' convert latitude to radian l = (Latitute / 180) * Pi ' Compute Longitude from great circle distance Longitute = 180 * Acos((Cos((d * 2 * Pi) / (2 * dblHalfEarth)) - Sin(l) * Sin(l)) / (Cos(l) * Cos(l))) / Pi ' Correct longitude sign if located in western hemisphere If Map.Distance(locSantaCruz, locX) < dblQuarterEarth Then Longitute = -Longitute End Sub End Class Disclaimer: Microsoft Licencing agreement requires every user to licence to use MS MapPoint. I hold no responsibility for use of this code by you. Basically you are at your own risk to use the above code. |
![]() |
| Tags |
| calc, code, geocode, licencing, question, setting |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DLL to reverse geocode with Mappoint 2004 | Anonymous | MapPoint 2006/2009 Discussion | 12 | 12-07-2005 05:54 PM |
| all altitudes increase about 10% after route calc | Anonymous | MapPoint 2006/2009 Discussion | 0 | 03-14-2005 05:59 AM |
| Setting Speeds | aarunprakash | MapPoint 2006/2009 Discussion | 0 | 06-06-2003 01:45 PM |
| Mappoint Licencing | Chris Lees | MapPoint 2006/2009 Discussion | 1 | 10-01-2002 08:03 PM |
| After you geocode a list of items from an excel fi.... | Anonymous | MapPoint 2006/2009 Discussion | 1 | 06-29-2000 08:00 PM |