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

Using BingGeocodeProvider without the MapControl

1 Answer 48 Views
Map
This is a migrated thread and some comments may be shown as answers.
Moochin
Top achievements
Rank 1
Moochin asked on 31 Mar 2011, 12:17 PM
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.
  Source=Telerik.Windows.Controls.DataVisualization
  StackTrace:
       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()
  InnerException:

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

 

 

 

 

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

 

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";
           _geocodeProvider.GeocodeAsync(request);
       }
       private void geocodeProvider_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e)
       {
           MapLocation = e.Response.Results[0].Locations[0]; 
           Working = false;
       }
   }

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 05 Apr 2011, 07:24 AM
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:

http://www.telerik.com/support/pits.aspx#/public/silverlight/2986

All the best,
Andrey Murzov
the Telerik team
Tags
Map
Asked by
Moochin
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or