Map is not showing

1 Answer 232 Views
Map
qwert
Top achievements
Rank 1
qwert asked on 23 Mar 2022, 10:07 AM

I have followed the guide https://docs.telerik.com/devtools/maui/controls/map/getting-started to integrate maps into my app. However, all I get is an empty white rectangle.

MainPage.xaml:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:telerikMap="clr-namespace:Telerik.XamarinForms.Map;assembly=Telerik.Maui.Controls.Compatibility"
             x:Class="MauiApp1.MainPage"
             BackgroundColor="{DynamicResource SecondaryColor}">

    <ScrollView>
        <Grid RowSpacing="25" HorizontalOptions="Fill" BackgroundColor="LightBlue" RowDefinitions="Auto, auto"
              Padding="{OnPlatform iOS='30,60,30,30', Default='20'}">
            <Grid Grid.Row="0" HeightRequest="600" BackgroundColor="Green">
                <telerikMap:RadMap x:Name="map" AutomationId="map">
                    <telerikMap:RadMap.Layers>
                        <telerikMap:ShapefileLayer>
                            <telerikMap:ShapefileLayer.Reader>
                                <telerikMap:MapShapeReader x:Name="reader"/>
                            </telerikMap:ShapefileLayer.Reader>
                        </telerikMap:ShapefileLayer>
                    </telerikMap:RadMap.Layers>
                </telerikMap:RadMap>              
            </Grid>                     
        </Grid>
    </ScrollView>
</ContentPage>

MainPage.xaml.cs:

using Telerik.XamarinForms.Map;
using Telerik.XamarinForms.ShapefileReader;

namespace MauiApp1;

public partial class MainPage : ContentPage
{
	public MainPage()
	{	
		InitializeComponent();

		var assembly = this.GetType().Assembly;
		var source = MapSource.FromResource("SDKBrowserMaui.Examples.MapControl.world.shp", assembly);
		this.reader.Source = source;

		Console.WriteLine("Source: " + source + "Reader: " + this.reader);
	}
}

Output:

Source: Telerik.XamarinForms.Map.StreamMapSource Reader: Telerik.XamarinForms.Map.MapShapeReader

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 23 Mar 2022, 11:25 AM

Hi qwert, 

I assume the reason behind this behavior is because you use wrong resource location.

You use this code:

var source = MapSource.FromResource("SDKBrowserMaui.Examples.MapControl.world.shp", assembly);
this.reader.Source = source;

The text marked in yellow is the location of the world.shp file. It is inside the MapControl folder. The example provided in the Getting Started article load.shp files as an embedded resources.  

You have to add the correct path where the .shp file is located in your project.

Regards,

Didi
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Map
Asked by
qwert
Top achievements
Rank 1
Answers by
Didi
Telerik team
Share this question
or