2011-07-08 45 views
1

我使用C#添加地址列表到MapPoint的。的MapPoint 2011 FindAddress對話框中的.NET

foreach (Stop stop in _stops) 
       _route.Waypoints.Add(_mpMap.FindAddressResults(stop.Street, stop.City, "", "Oregon", stop.Zip)[1]); 

有時地址格式是錯誤的,因爲我得到崩潰或錯誤的地址。

MapPoint中(應用程序),你可以搜索地點,如果的MapPoint找到多個或您在地址錯誤,它會打開一個查找併爲您提供選項來搜索和/或仍要添加地址。

例子: enter image description here

注意輸入的地址是如何被格式化很少,但是mapoint可以輕鬆找到完整的地址與正常格式。有時會有更多結果,如果發生這種情況,我需要手動選擇。問題:如何?

後來添加上:

我可以調用對話框本身與方法ShowFindDialog,我可以得到.Count之間的參數

MapPoint.FindResults results = _mpMap.FindAddressResults(stop.Street, stop.City, "", "Oregon", stop.Zip); 
MessageBox.Show("Found " + results.Count + " results"); 

發現結果的計數,但我不能找到一種方法指定地址ShowFindDialog

回答

2

你濫用FindAddressResults。這不會返回一個簡單的數組(這是你如何對待它),而是一個FindResults集合。 的FindResults藏品包括一個名爲「ResultsQuality」屬性。這是在附帶的MapPoint的幫助文件完全記錄,但你必須檢查此值之前,盲目地假定集合包含一個或多個結果!

的ResultsQuality屬性設置爲一個GeoFindResultsQuality枚舉。您想檢查geoAllResultsValid(0)或geoFirstResultGood(1)。其他值表示沒有結果或ambiguus結果。

下面是從文檔VB6的例子:

Sub AddPushpinToGoodFindMatch() 

Dim objApp As New MapPoint.Application 
Dim objFR As MapPoint.FindResults 

'Set up the application 
objApp.Visible = True 
objApp.UserControl = True 

'Get a FindResults collection 
Set objFR = objApp.ActiveMap.FindResults("Seattle") 

'If the first result is a good match, then use it 
If objFR.ResultsQuality = geoFirstResultGood Then 
    objApp.ActiveMap.AddPushpin objFR.Item(1) 
Else 
    MsgBox "The first result was not a good match." 
End If 

End Sub 

FindResults()是返回相同FindResults類的舊方法,但使用FindAddressResults(因爲你正在做的)一般是一個更好的事情。


附錄:由於這個普遍的問題是這樣一個共同的問題(可能是由於在MapPoint的文檔是一味削減&粘貼壞的示例代碼),我寫了一篇文章關於using the FindResults collection correctly,對我的「的MapPoint HowTo「頁面。

相關問題