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)
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
;
}
}