Failed to create a 'System.Device.Location.GeoCoordinate' from the text (problem - solution)
When You test code included in book Windows Phone 7 (..) by Henry Lee, Eugene Chuvyrov You can reach the moment when You get above error. Problem is related to the situation when Pushpin's Content depends on the object that has not been created yet.
- <BingMap:Map x:Name="bingMap" ZoomLevel="4" ZoomBarVisibility="Visible"
- CopyrightVisibility="Collapsed" LogoVisibility="Collapsed" Grid.Row="2">
- <BingMap:Pushpin Name="bingMapLocator">
- <Ellipse Fill="Red" Width="20" Height="20" BingMap:MapLayer.Position="0,0" Name="Locator"/>
I commented out the part of code which I decided to move to the code behind file, check this:
- Location location = new Location();
- location.Latitude = latitude;
- location.Longitude = longitude;
- bingMap.SetView(location, zoomLevel);
- MapLayer.SetPosition(this.bingMapLocator, location);
Above code is related to setting position of Pushpin - in XAML and by default it was set in 0,0 (latitude & longitude) position and that is the moment when application crashes. MapLayer.SetPosition == BingMap:MapLayer.Position - so if You decide to move BingMap:MapLayer.Position code from XAML and set it in code behind using MapLayer.Position - it will work. I decided to do a little more than that in code behind (additionally I created Pushpin's Content in code behind - You don't have to) - You can decide to choose one of those two solutions.
Now it works. After InitializeComponent() method I am sure that when I decide to set Pushpin's Content - that object exists and I won't get this error again.