如何使用必应地图获取地理编码? [英] How to get geocodes using bing maps?

查看:119
本文介绍了如何使用必应地图获取地理编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了一个代码段,该代码段使用bing映射从地址中检索地理位置代码.简单的第一行从配置管理器获取一个密钥.但是,当代码执行时,此行不会检索任何内容.因此,该功能的其余部分无法正常工作.这是代码段:

I downloaded a code snippet which uses the bing maps to retrive geo codes from an address. The first line of the simply gets a key from the configuration manager. However, when the code executes this line does not retrieve anything. So the rest of the function does not work properly. Here is the code snippet:

Private Sub MakeGeocodeRequest(Byval Address As string)

        Try
            ' Set a Bing Maps key before making a request
            Dim key As String = System.Configuration.ConfigurationManager.AppSettings("BingMapsAPIKey")
            Dim geocodeRequest As New bing.geocode.GeocodeRequest
            Dim SearchAddress As String = Address
           If SearchAddress.Contains("UK") = False Then
                SearchAddress += ", UK"
            End If

            ' Set the credentials using a valid Bing Maps Key
            geocodeRequest.Credentials = New bing.geocode.Credentials()
            geocodeRequest.Credentials.ApplicationId = key

            ' Set the full address query
            geocodeRequest.Query = SearchAddress

            ' Set the options to only return high confidence results
            Dim filters As bing.geocode.ConfidenceFilter() = New bing.geocode.ConfidenceFilter(0) {}
            filters(0) = New bing.geocode.ConfidenceFilter()
            filters(0).MinimumConfidence = bing.geocode.Confidence.High

            Dim geocodeOptions As New bing.geocode.GeocodeOptions()
            geocodeOptions.Filters = filters

            geocodeRequest.Options = geocodeOptions

            ' Make the geocode request
            Dim geocodeService__1 As New bing.geocode.GeocodeService

            'If there's a proxy set in the appsettings of the web.config then use it
            If Not String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings("Proxy")) Then
                geocodeService__1.Proxy = New System.Net.WebProxy(System.Configuration.ConfigurationManager.AppSettings("Proxy"))
            End If

            Dim geocodeResponse As bing.geocode.GeocodeResponse = geocodeService__1.Geocode(geocodeRequest)

            If geocodeResponse.Results.Count > 0 AndAlso geocodeResponse.Results(0).Locations.Count > 0 Then
                debug.print("Lat:" & geocodeResponse.Results(0).Locations(0).Latitude)
                debug.print("Long:" & geocodeResponse.Results(0).Locations(0).Longitude)
            End If

        Catch ex As Exception
            Debug.Print(ex.Message)
        End Try
    End Sub



我已将bing地图添加为网络参考.但是它仍然行不通.请帮忙!!!

我收到一条错误消息,说我的程序无法连接到bing服务器.同样,它们起作用的第一行获取bing map api键,它什么也不返回.



I''ve added bing maps as a web reference. But still it doesn''t work. Please help!!!

I get an error saying that my program can''t connect to the bing server. Also the first line where they function get the bing map api key, it returns nothing.

推荐答案

1.您必须更改
1. You have to change
... As New bing.geocode.GeocodeService







to

...As New bing.geocode.GeocodeServiceClient("BasicHttpBinding_IGeocodeService")



2.现在,您将收到错误:凭据无效或未指定".
在这里,您必须获取CredentialProvider密钥,因为



2. Now you will get the error:"Credentials are either invalid or unspecified".
Here you have to aquire CredentialProvider key because

BingMapsAPIKey

是不够的.

但是您可以尝试(只是为了检查其工作原理).

is not enough.

But you can try this (just to check how it works).


我发现了引起问题的原因.我真是个白痴.该功能从一开始就正常工作.就在前一段时间,我只是在Visual Studio 2010中启用了一个选项,尝试进入第三方代码.因此,该错误是由于.net调试器尝试进入bing maps服务器而导致的.

现在,我需要一个帮助.我不记得我启用的选项的确切名称.所以任何人都可以告诉我该怎么做吗?
I found what''s causing the problem. I''m such an idiot. The function was working right from the start. It''s that some time ago I just enables an option in Visual Studio 2010 where it tries to step into third party code. So, the error come as a result of the .net debugger trying to step into the bing maps server.

Now, I need one help. I don''t remember the exact name of the option I enables. So can anyone please tell me what to do??


这篇关于如何使用必应地图获取地理编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆