This is a migrated thread and some comments may be shown as answers.

How to use BingGeocodeProvider ?

2 Answers 126 Views
Map
This is a migrated thread and some comments may be shown as answers.
Sebastian Talamoni
Top achievements
Rank 1
Sebastian Talamoni asked on 24 Mar 2010, 03:45 PM
Hi,

I am trying to use the GeoCodeAsync to find the Location of a given address.
I get a response == Success but NO result results ( e.Response.Results == 0 )
Doing the same from the Bing webpage works fine (finds the address and shows the map).

   private void Button_Click(object sender, RoutedEventArgs e) 
        { 
 
            var bing = new BingGeocodeProvider { MapControl = RadMap1 };            
            bing.ApplicationId = BingMapHelper.VEKey ; 
            bing.GeocodeCompleted += bing_GeocodeCompleted; 
 
            var address = new Address { AddressLine = addressLine.Text }; 
            var request = new GeocodeRequest { Address = address }; 
            bing.GeocodeAsync(request); 
        } 
 
        void bing_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e) 
        { 
            var summary = e.Response.ResponseSummary; 
            if ( summary.StatusCode == ResponseStatusCode.Success) 
            { 
                var results = e.Response.Results; 
                 
            } 
 
        } 




2 Answers, 1 is accepted

Sort by
0
Sebastian Talamoni
Top achievements
Rank 1
answered on 24 Mar 2010, 04:30 PM
Further information :

1)  Using your silverlight demo app  and typing the same address works fine.
2) Creating a bing account and replacing the original demo VEKEy does not help either.
(VEKey = "AhLlRzBWylY8gMY5wLhyuckRQ0PQVbVKnTwdTiid5dNIeyP59nYQ6Tb0y_485DQi") 
  What's exactly the VEKEY? Creating an app in BING gives a completely different (size) token/id.

3) Exceptions in the GeoCode process are not correctly catched.
I am expecting here either an OnError event  , or that the Completed event gets called with Status= Failed.

4) Attached is a unit test that shows the problem

Exception:

System.Exception was unhandled 
  Message=Route Service Exception: An exception occurred during the operation, making the result invalid.  Check InnerException for exception details. 
  Source=Telerik.Windows.Controls.DataVisualization 
  StackTrace: 
       at Telerik.Windows.Controls.Map.BingGeocodeProvider.GeocodeServiceGeocodeCompleted(Object sender, GeocodeCompletedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\DataVisualization\Map\Providers\Geocode\BingGeocodeProvider.cs:line 250 
       at Telerik.Windows.Controls.Map.WPFBingGeocodeService.GeocodeServiceClient.OnGeocodeCompleted(Object state) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\DataVisualization\Service References\WPFBingGeocodeService\Reference.cs:line 1638 
       at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) 
       at System.Threading.ExecutionContext.runTryCode(Object userData) 
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
       at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 
       at System.Threading.ThreadPoolWorkQueue.Dispatch() 
       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 
  InnerException:  
 


Unit Test: 

using System; 
using Microsoft.VisualStudio.TestTools.UnitTesting; 
using Telerik.Windows.Controls; 
using Telerik.Windows.Controls.Map; 
 
namespace TestProject1 
    [TestClass] 
    public class UnitTest1 
    { 
        private bool finished = false
        public const string VEKey = "AhLlRzBWylY8gMY5wLhyuckRQ0PQVbVKnTwdTiid5dNIeyP59nYQ6Tb0y_485DQi"; 
 
        [TestMethod] 
        public void TestMethod1() 
        { 
            var map = CreateDefaultMap(); 
            var bing = new BingGeocodeProvider { MapControl = map }; 
            bing.GeocodeCompleted += bing_GeocodeCompleted; 
            var address = new Address 
                              { 
                                  PostalCode = "3512"
                                  PostalTown = "Utrecht"
                                  AddressLine = "Domplein 9, 3512 Utrecht, Nederland" 
                              }; 
            var request = new GeocodeRequest { Address = address }; 
            bing.GeocodeAsync(request); 
 
            while (!finished ) 
            { 
                System.Threading.Thread.Sleep( TimeSpan.FromSeconds(1)); 
            } 
        } 
 
        private RadMap CreateDefaultMap() 
        { 
            var radMap = new RadMap 
                             { 
                                 Provider = CreateDefaultProvider(), 
                                 Center = new Location(42.697872, 23.321583), 
                                 ZoomLevel = 7 
                             }; 
            return radMap; 
        } 
 
        private IMapProvider CreateDefaultProvider() 
        { 
            var provider = new BingMapProvider(MapMode.Road, true, VEKey); 
            return provider; 
        } 
 
        void bing_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e) 
        { 
            finished = true
        } 
    } 
 
 


Thanks in advance, 
Sebastian Talamoni
0
Sebastian Talamoni
Top achievements
Rank 1
answered on 24 Mar 2010, 05:30 PM
Ok, found my problem.

the answer is simple: i was using the Address whereas I should have used the Query property.

Found the answer thanks to this post:
http://www.telerik.com/community/forums/silverlight/map/can-t-get-geocodeasync-to-work.aspx




Tags
Map
Asked by
Sebastian Talamoni
Top achievements
Rank 1
Answers by
Sebastian Talamoni
Top achievements
Rank 1
Share this question
or