Using BingGeocodeProvider without the MapControl

2 posts, 0 answers
  1. Moochin
    Moochin avatar
    3 posts
    Member since:
    Sep 2012

    Posted 31 Mar 2011 Link to this post

    Is it possible to use BingGeocodeProvider without setting the .MapControl property? I'm using Prism with WPF and I want to be able to create the location for the map in the view model, and databind the RadMap control 'Centre' property to my view model 'MapLocation' property. Currently I get the following error.

    System.Exception was unhandled
      Message=Routing Service Exception: Route Service Exception: Object reference not set to an instance of an object.
           at Telerik.Windows.Controls.Map.BingGeocodeProvider.GeocodeAsync(GeocodeRequest request) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\DataVisualization\Map\Providers\Geocode\BingGeocodeProvider.cs:line 88
           at DataAggregator.Modules.Cube.ViewModels.MapViewModel.RequestPersonalDataEvent(Person person)
           at Microsoft.Practices.Prism.Events.BackgroundEventSubscription`1.<>c__DisplayClass5.<InvokeAction>b__4(Object o)
           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()

    Example XAML (with some bits removed to keep it simple)





        <telerik:RadMap x:Name="mapControl" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Provider="{Binding MapProvider}" Center="{Binding MapLocation}"/>


    public class MapViewModel : ViewModelBase
           const string _apiKey = "{key}";
           private readonly IEventAggregator _eventAggregator;
           private BingGeocodeProvider _geocodeProvider;
           private MapProviderBase _mapProvider;
           public MapProviderBase MapProvider
               get { return _mapProvider; }
               set { _mapProvider = value; }
           private Location _mapLocation;
           public Location MapLocation
               get { return _mapLocation; }
               set { _mapLocation = value; this.RaisePropertyChanged(() => this.MapLocation); }
           public MapViewModel(IEventAggregator eventAggregator)
               _eventAggregator = eventAggregator;
               _eventAggregator.GetEvent<Infrastructure.RequestPersonalDataEvent>().Subscribe(this.RequestPersonalDataEvent, ThreadOption.BackgroundThread);
               _mapProvider = new BingMapProvider(MapMode.Aerial, true, _apiKey);
           public void RequestPersonalDataEvent(Infrastructure.Models.Person person)
               this.Working = true;
               _geocodeProvider = new BingGeocodeProvider(_apiKey);
               _geocodeProvider.GeocodeCompleted += this.geocodeProvider_GeocodeCompleted;
               GeocodeRequest request = new GeocodeRequest();
               request.Query = "Postcode";
           private void geocodeProvider_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e)
               MapLocation = e.Response.Results[0].Locations[0]; 
               Working = false;
  2. Andrey
    Andrey avatar
    1681 posts

    Posted 05 Apr 2011 Link to this post

    Hello Moochin,

    Presently, it is not possible to use BingGeocodeProvide without setting the MapControl property in the current version of the RadMap control. We are planning to change it in the future releases. You can track the availability of this feature using our PITS system:

    All the best,
    Andrey Murzov
    the Telerik team
  3. DevCraft R3 2016 release webinar banner
Back to Top