ThinkGeo.com    |     Documentation    |     Premium Support

Unable to display a simple map

Guys, I am evaluating the Windows Phone SDK but cannot get a simple map to display.  Application throws a NullReferenceException with details listed below:



System.NullReferenceException was unhandled
Message: An unhandled exception of type ‘System.NullReferenceException’ occurred in System.Windows.ni.dll
Additional information: Object reference not set to an instance of an object.



The XAML is simple enough:




<phone:PhoneApplicationPage
    x:Class=“PhoneApp2.Thgeo.MapView”
    xmlns="<a href=“schemas.microsoft.com/winfx/2006/xaml/presentation” tabindex=“0”>schemas.microsoft.com/winfx/...esentation</a>"
    xmlns:x="<a href=“schemas.microsoft.com/winfx/2006/xaml” tabindex=“0”>schemas.microsoft.com/winfx/2006/xaml</a>"
    xmlns:phone=“clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone”
    xmlns:shell=“clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone”
    xmlns:d="<a href=“schemas.microsoft.com/expression/blend/2008” tabindex=“0”>schemas.microsoft.com/expression/blend/2008</a>"
    xmlns:mc="<a href=“schemas.openxmlformats.org/markup-compatibility/2006” tabindex=“0”>schemas.openxmlformats.org/m...ility/2006</a>"
    xmlns:windowsPhoneEdition=“clr-namespace:ThinkGeo.MapSuite.WindowsPhoneEdition;assembly=WindowsPhoneEdition”
    mc:Ignorable=“d”
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations=“Portrait” Orientation=“Portrait”
    shell:SystemTray.IsVisible=“True”>
     
    <phone:PhoneApplicationPage.Resources>
        <Style TargetType=“ListBoxItem”>
            <Setter Property=“HorizontalContentAlignment” Value=“Stretch”/>
        <!–</code–>Style>

    <!–</code–>phone:PhoneApplicationPage.Resources>

 
    <!–LayoutRoot is the root grid where all page content is placed–>
    <Grid x:Name=“LayoutRoot” Background=“Transparent”>
        <Grid.RowDefinitions>
            <RowDefinition Height=“Auto”/>
            <RowDefinition Height="*"/>
        <!–</code–>Grid.RowDefinitions>

 
        <!–TitlePanel contains the name of the application and page title–>
        <StackPanel x:Name=“TitlePanel” Grid.Row=“0” Margin=“12,17,0,28”>
            <TextBlock Text=“MY APPLICATION” Style="{StaticResource PhoneTextNormalStyle}" Margin=“12,0”/>
            <TextBlock Text=“page name” Margin=“9,-7,0,0” Style="{StaticResource PhoneTextTitle1Style}"/>
        <!–</code–>StackPanel>

 
        <!–ContentPanel - place additional content here–>
        <Grid x:Name=“ContentPanel” Grid.Row=“1” Margin=“12,0,12,0”>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height=“Auto”/>
            <!–</code–>Grid.RowDefinitions>

            <windowsPhoneEdition:Map Name=“Map” Width=“Auto” Height=“Auto”/>
          
             
            <StackPanel Grid.Row=“1” Orientation=“Horizontal”>
                <Button Command="{Binding AddPointsCommand}" Width=“100”>
                    <Image Source="…/Toolkit.Content/ApplicationBar.Add.png"><!–</code–>Image>

                <!–</code–>Button>

                <Button Command="{Binding AddLineCommand}" Width=“100”>
                    <Image Source="…/Toolkit.Content/ApplicationBar.Add.png"><!–</code–>Image>

                <!–</code–>Button>

                <Button Command="{Binding AddPolygonCommand}" Width=“100”>
                    <Image Source="…/Toolkit.Content/ApplicationBar.Add.png"><!–</code–>Image>

                <!–</code–>Button>

                <Button Command="{Binding ShowLegendCommand}" Width=“100”>
                    <Image Source="…/Toolkit.Content/ApplicationBar.Select.png"><!–</code–>Image>

                <!–</code–>Button>

            <!–</code–>StackPanel>

        <!–</code–>Grid>

    <!–</code–>Grid>

 
<!–</code–>phone:PhoneApplicationPage>







as well as the code behind:





   

public partial class MapView : IMapView
    {
        LayerOverlay _dynamicLayerOverlay = new LayerOverlay(“dlo”);
        public MapView()
        {
            InitializeComponent();            
            Map.MapUnit = GeographyUnit.DecimalDegree;
            Map.Overlays.Add(new WorldMapKitWmsWindowsPhoneOverlay());            
            Loaded += DisplayASimpleMap_Loaded;
        }
 
        void DisplayASimpleMap_Loaded(object sender, RoutedEventArgs e)
        {
            Map.CurrentExtent = new RectangleShape(-135.7, 83.6, 113.5, -53);
        }
 
        private void InitializeMapComponent()
        {
           //  Map.ZoomLevel = 2;
        }
}




But when I run this, the application just crashes, even though I copied this from one of the samples, which I also runs fine. 



Do not know if this matters, but I am running this on a virtual machine.  





Any ideas?  


Hi Klaus,



I test the Window Phone edition 7.0.0.0 in my machine, but all the samples works fine. Here is my machine environment:

OS: window 8.1 x64

Emulator WVGA 512MB

VS: vs 2012



As you mentioned you are developed it in a virtual machine, I am trying to setup a virtual machine in a window 8.1 machine. But still downloading the SDK 8.0, I will update here once I test the window phone edition 7.0 in this machine.



Before that, may be we can try the below ways to narrow down this issue:


        
  • skip map suite production, just create a basic WP application to see if the application works fine. I am just guessing your window phone development environment is not correct.

  •     
  • following our Windows_Phone_Edition_Quick_Start_Guide to build a simple map application. 


Thanks,

Troy


Tony, thanks for the response.  



Our setup is a little different.  Mine is: 

OS: Windows 7 x64 

VM : VMWare 

VS: VS 2013  



I am able to run all of CSharp VS2012 HowDoISamples and also can run a simple Windows Phone 8 app. As soon as I add a MapSuite map control to my main page, application crashes. 



However, I have been able to narrow it down to this line in the XAML:

<windowsphoneedition:map name="Map" width="Auto" height="Auto">


<windowsPhoneEdition:Map Name="Map" Width="Auto" Height="Auto" />

<windowsphoneedition:map name="Map" width="Auto" height="Auto">

If I set a fixed width and height on the Map control as follows:



<windowsphoneedition:map name="Map" width="480" height="760">  <windowsPhoneEdition:Map Name="Map" Width="480" Height="760" />



Application appears to run fine.  If I set the width and height to "Auto" application crashes. I can live with this for now, since this is mostly evaluation.  It would be good to have an official solution for this problem though. 



Klaus 



</windowsphoneedition:map></windowsphoneedition:map></windowsphoneedition:map>

Hi Klaus,



Good to hear you have figured it out.

As for the auto size of the map, actually, out map control can support it, I try the below codes in HowDoI sample=> DisplayASimpleMap and it works fine:


<UserControl x:Class=“CSharp_Samples.DisplayASimpleMap”
    xmlns="<a href=“schemas.microsoft.com/winfx/2006/xaml/presentation” tabindex=“0”>schemas.microsoft.com/winfx/...esentation</a>"
    xmlns:x="<a href=“schemas.microsoft.com/winfx/2006/xaml” tabindex=“0”>schemas.microsoft.com/winfx/2006/xaml</a>"
    xmlns:cc1=“clr-namespace:ThinkGeo.MapSuite.WindowsPhoneEdition;assembly=WindowsPhoneEdition”
    xmlns:DragPanel=“clr-namespace:ControlForDragPanel;assembly=ControlForToolTips”
    Width=“800” Height=“600”>
    <Grid x:Name=“LayoutRoot” Background=“White” Loaded=“DisplayASimpleMap_Loaded”>
        <cc1:Map x:Name=“Map1”  Width=“Auto” Height=“Auto”  Background="#e5e3df"></cc1:Map>
        <DragPanel:DragPanel x:Name=“DescInfo” Title=“Instructions”>
            <TextBlock x:Name=“TextBlock1” TextWrapping=“Wrap” Text=“This sample simply uses ThinkGeo default world map kit service overlay.”></TextBlock>
        </DragPanel:DragPanel>
    </Grid>
</UserControl>

BTW, we have two new upcoming products in map suite family: map suite for android and IOS, both of them are built from c#. Hope you also enjoy them. thinkgeo.com/forums/MapSuite…fault.aspx



Thanks,

Troy