Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use MapInfo's Mapmarker Geocoding with VFP
Message
De
19/11/2002 09:18:54
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Produits tierce partie
Divers
Thread ID:
00723501
Message ID:
00724257
Vues:
86
As you requested, here's, I hope, a good synopsis:

The Mapinfo VB example uses the MapmarkrCtrl ActiveX control to provide geocode support on a form.

Four subroutines on the form seem to control the functionality I'm looking to implement through Foxpro:

---FORM LOAD SUB:

...Key code statement:

Private Sub Form_Load()
Set objMM = CreateObject("MAPMARKR.MapMarkrCtrl.1")
bConnected = False
bSettingModified = False
cmdGeocode.Enabled = False
cmdCentroid.Enabled = False
cmdGetCand.Enabled = False
cmdFreeSet.Enabled = False
cmdDisconnect.Enabled = False
txtlastline.Visible = False
Label21.Visible = False

With objMM
txtServer = .ServerName
lblBinding = .StringBinding
ExeName = .GetName
If .ExactHouse = True Then
chkMatchHouse.Value = 1
Else
chkMatchHouse.Value = 0
End If
If .ExactName = True Then
chkMatchStreet.Value = 1
Else
chkMatchStreet.Value = 0
End If
If .ExactZip = True Then
chkMatchCentroid.Value = 1
Else
chkMatchCentroid.Value = 0
End If
If .ExpandSearch = True Then
chkExtendedSearch.Value = 1
Else
chkExtendedSearch.Value = 0
End If
If .ExpandSearchInState = True Then
chkInState.Value = 1
Else
chkInState.Value = 0
End If
If .MatchIntersections = True Then
chkMatchXsec.Value = 1
Else
chkMatchXsec.Value = 0
End If
txtDistance = .ExpandDistance
txtOffsetLine = .LinearOffset
txtOffsetPerp = .PerpendicularSetback
End With

End Sub


---OPTION2 OPTION SUB

On the sample form, clicking the Option2 radio button tells the MapMarkrCtrl that it must use its local .DLL rather than a geocoding server. The program duly notes this fact and proceeds to setup and verify the presence of the geocoding database and contained addresses. Once completed, the critical method, GeocodeAddress(), can be used:

...Key Code statements:

Private Sub Option2_Click()
Dim serverVersion As Double
Dim txtBuf As String
objMM.NotUsingServer = True
cmdConnect.Enabled = False
cmdGeocode.Enabled = True
cmdCentroid.Enabled = True
txtServer.Enabled = False
txtDbAvailable = objMM.GeocodeCheckDbAvailability
DatabaseTypes = objMM.DatabaseTypes
retVal = objMM.GeocodeGetServerVersion(serverVersion)
txtVersion = Str$(serverVersion)
retVal = objMM.GeocodeGetStatesLicensed(txtBuf)
txtLicensed = txtBuf
retVal = objMM.GeocodeGetStatesFound(txtBuf)
txtAvailable = txtBuf
ExeName = objMM.GetName
End Sub


---GEOCODE BUTTON SUB:

After the user clicks the "Geocode" button, many label and text fields are cleared on the form. Depending on option settings re: using a full address, a street intersection, or a zip code, the button calls the critical geocoding method [GeocodeAddress()] that can yield 0 or 1 or many matches called "candidates". The subprogram finishes by storing whether 0 or 1 ("Single-Match") or many possible candidates were found and enabling the two candidate display buttons:

...Key code statments:

Private Sub cmdGeocode_Click()
Dim retVal As Boolean
Dim retCode
Dim errorCode&
' User changed geocoding config parameters
If bSettingModified = True Then
retCode = MsgBox("Config parameters have been changed. Do you want to use new parameters?", 3, "Street Geocoding")
If retCode = vbYes Then
cmdSet_Click
ElseIf retCode = vbCancel Then
Exit Sub
End If
End If
lblLong = ""
lblLat = ""
lblPrec = ""
lblStatus = ""
lblCand = ""
lstCandidates.Clear
On Error GoTo GeocodeAddress_Error
If chklastline.Value = 1 Then
retVal = objMM.GeocodeAddressLastline(lngEngHandle, txtFirm, txtStreet, txtlastline, status, numCandidates, numCloseCandidates)
Else
retVal = objMM.GeocodeAddress(lngEngHandle, txtFirm, txtStreet, txtCity, txtState, txtZip, status, numCandidates, numCloseCandidates)
End If
On Error GoTo 0
If Not retVal Then
errorCode = objMM.LastErrorCode
If errorCode = 14 Then
lblStatus = "Invalid address"
'Sometimes .Connect returns true even server not
'running, but .GeocodeAddress will return 1753
ElseIf errorCode = 1753 Then
If txtServer = "" Then
lblStatus = "Local server is not running"
Else
lblStatus = "Server : " & txtServer & " is not running"
End If
Else
lblStatus = "Error geocoding, error code: " & Str$(errorCode)
End If
Else
DatabaseTypes = objMM.DatabaseTypes
Select Case status
Case 0
lblStatus = "Single match"
Case 1
lblStatus = "Multiple match"
Case 2
lblStatus = "No close matches"
Case 3
lblStatus = "No candidates"
Case 4
lblStatus = "Single intersection match"
Case 5
lblStatus = "Multiple intersection match"
Case 6
lblStatus = "No close intersection matches"
Case 7
lblStatus = "No intersection candidates"
Case 8
lblStatus = "Possible intersections"
Case Else
lblStatus = Str$(status)
End Select
If numCandidates > 0 Then
lblCand = Str$(numCandidates)
'Now .GetCandidates can be called to get
'candidate information
cmdGetCand.Enabled = True
cmdFreeSet.Enabled = True
Else
cmdGetCand.Enabled = False
cmdFreeSet.Enabled = False
End If
End If
Exit Sub
GeocodeAddress_Error:
lblStatus = "Error geocoding"
End Sub


---GET CANDIDATES BUTTON SUB

A Single-Match candidate means enough information exists for the geocoding logic to narrow the choices to one database address entry. Otherwise, assuming > 1 candidates, a potential list of possibilities exists. Clicking the button to display candidates reveals the choices as added to a list box on the form. I'm after the adr.Latitude and adr.Longitude values:

...Key Code Statements:

Private Sub cmdGetCand_Click()
Dim adrList As CAddressList
Dim adr As CAddress
Dim strAddr$, strCoords$, strPrec$, strCensId$
On Error GoTo GeocodeGetCandidates_Error
Set adrList = objMM.GeocodeGetCandidates(lngEngHandle, numCandidates)
On Error GoTo 0
'Fill in the ListBox with the candidates
lstCandidates.Clear
For Each adr In adrList
With adr
If IsEmpty(.Firm) Or .Firm = "" Then
strAddr = .Street & ", " & .City & ", " & .State & " " & .Zip & "-" & .plus4
Else
strAddr = .Firm & ", " & .Street & ", " & .City & ", " & .State & " " & .Zip & "-" & .plus4
End If
strCoords = " (" & Format(.Latitude, "##0.0000") & ", " & Format(.Longitude, "##0.0000") & ")"
Select Case .Precision
Case 30
strPrec = " Street-level (Xsect) "
Case 20
strPrec = " Street-level "
Case 10
strPrec = " Shape-path Cent. "
Case 3
strPrec = " Zip+4 "
Case 2
strPrec = " Zip+2 "
Case 1
strPrec = " Zip centroid "
End Select
strCensId = .CensusBlock
End With
Set adr = Nothing
lstCandidates.AddItem (strAddr & strCoords & strPrec & strCensId)

Next
Set adrList = Nothing
Exit Sub

GeocodeGetCandidates_Error:
MsgBox "Error getting candidates"
End Sub
-------------------------------------------------------------------------------------------------------

I know this all looks relatively straightforward, but when I try to instantiate the MapMarkrCtrl and use it in a .prg, it simply seems not to like the flavor of the strings and numbers that I pass it as well as it does when VB passes them.

Zooming in on the GeocodeAddress function, here are some other points to make:

GeocodeAddress(lngEngHandle, txtFirm, txtStreet, txtCity, txtState, txtZip, status, numCandidates, numCloseCandidates)

INPUT PARAMETERS:

Firm - string name of person or organization
Street - string street address (can be intersection with component streets separated by &&)
City - string city
State - string state (2 char)
Zip - string 5-digit zipcode

OUTPUT PARAMETERS:

EngHandle - long Geocoding engine handle assigned to this geocode request
Status - integer code for result ("Single-Match" best, indicates a solid choice on 1 address)
Candidates - integer count of candidates tagged
CloseCandidates - integer count of candidates closely matching address
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform