Click here to Skip to main content
15,907,396 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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


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.
Posted
Updated 18-Jul-11 19:35pm
v3
Comments
Prerak Patel 19-Jul-11 1:30am    
What error you get? Be specific.

1. You have to change
... As New bing.geocode.GeocodeService


to

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


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).
 
Share this answer
 
v2
Comments
obhasha07 20-Jul-11 3:03am    
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??
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??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900