.NET 中的 MapPoint 2011 FindAddress 对话框

发布于 2024-11-19 06:51:45 字数 832 浏览 8 评论 0原文

我使用 C# 将地址列表添加到 Mappoint 中。

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

有时地址格式错误,因此我要么崩溃,要么地址填写错误。

在mappoint(应用程序)中,您可以搜索地点,如果mappoint找到多个地点或者您在地址中犯了错误,它会打开一个查找并为您提供搜索和/或添加地址的选项。

例子: 在此处输入图像描述

请注意输入的地址格式不正确,但 mapoint 可以轻松找到具有正常格式的完整地址。有时会有更多结果,如果发生这种情况,我需要能够手动选择。问:如何?

稍后添加:

我可以使用方法 ShowFindDialog 调用对话框本身,并且可以使用 .Count 参数获取找到的结果数

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

,但我找不到指定地址的方法到ShowFindDialog

I am adding a list of addresses into Mappoint using C#.

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

Sometimes address format is wrong and because of that I get either crash or complected wrong address.

In mappoint (application) you can search for places and if mappoint finds multiple or you make a mistake in address, it opens a find and gives you options to search and/or add address anyway.

Example:
enter image description here

Notice how entered address is poorly formatted, but mapoint could easly find full address with normal formatting. Sometimes there are more results and I need to be able to select manually if that happens. Question: How?

Added later on:

I can call dialog itself with method ShowFindDialog and I can get the count of results found with .Count parameter

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

But I can't find a way to specify address to ShowFindDialog

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红尘作伴 2024-11-26 06:51:45

您正在滥用 FindAddressResults。这不会返回一个简单的数组(这就是您处理它的方式),而是返回一个 FindResults 集合。
FindResults 集合包含一个名为“ResultsQuality”的属性。 MapPoint 附带的帮助文件中对此进行了完整记录,但在盲目假设集合包含一个或多个结果之前,您必须检查该值!

ResultsQuality 属性设置为 GeoFindResultsQuality 枚举。您想要检查 geoAllResultsValid (0) 或 geoFirstResultGood (1)。其他值表示没有结果或结果不明确。

下面是文档中的 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 文档中盲目剪切和粘贴的错误示例代码),我写了一篇关于 正确使用 FindResults 集合,位于我的“MapPoint HowTo”页面上。

You are abusing FindAddressResults. This does not return a simple array (which is how you are treating it), but a FindResults collection.
The FindResults collection includes a property called "ResultsQuality". This is fully documented in the help file that comes with MapPoint, but you must check this value before blindly assuming the collection contains one or more results!

The ResultsQuality property is set to a GeoFindResultsQuality enumeration. You want to check for geoAllResultsValid (0) or geoFirstResultGood (1). The other values indicate no results or ambiguus results.

Here's the VB6 example from the docs:

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() is an old method which returns the same FindResults class, but using FindAddressResults (as you are doing) is generally a much better thing to do.


Addenda: As this general problem is such a common problem (probably due to bad sample code in the MapPoint docs that is blindly cut&pasted), I've written an article about using the FindResults collection correctly, on my "MapPoint HowTo" pages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文