I’m trying to set the lat/lng values for the item marked "<device:GeoCoordinate..." dynamically. I can hard code this in the XAML no problem but when I attempt to set it on the fly I get a null pointer exception (inside the loaded handler shown below)
XAML
<maps:Map ZoomLevel="6" Mode="Aerial" Grid.Row="1" Grid.ColumnSpan="2">
<maps:Map.Center>
<device:GeoCoordinate x:Name="theLocation"/>
</maps:Map.Center>
<maps:MapLayer x:Name="TheMapLayer"/>
</maps:Map>
c#
void ViewBingMaps_Loaded(object sender, RoutedEventArgs e)
{
//get lat + lng for the device and set it dynamically
theLocation.Latitude = 41.5686949;
theLocation.Longitude = -93.7943157;
}
Is it possible to set this or am I misunderstanding the device:GeoCoordinate purpose?
Simply re-instantiate the
GeoCoordinateclass in the code-behind and set the map center to it: