1

I'm trying to load street map using Xamarin.Forms.Map plugin in my project for UWP app. For that I have also get the token from MSDN. Here is what I have done:

MapePage.xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:vm="clr-namespace:Map_POC.ViewModels" 
             xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps" 
             xmlns:local="clr-namespace:Map_POC.CustomControls"
             x:Class="Map_POC.Views.MapePage">
    <ContentPage.BindingContext>
        <vm:MapePageViewModel />
    </ContentPage.BindingContext>
    <ContentPage.Content>
        <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <maps:Map
                x:Name="MyMap"
                HorizontalOptions="FillAndExpand" 
                VerticalOptions="FillAndExpand"     
                MapType="Street" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

MapePage.xaml.cs

public MapePage()
{
    InitializeComponent();
    
    Position position = new Position(-37.8141, 144.9633);

    var pin = new Pin
    {
        Type = PinType.Place,
        Position = position,
        Label = "I'm a Pin",
    };

    MyMap.Pins.Add(pin);

    MyMap.MoveToRegion(
        MapSpan.FromCenterAndRadius(
            position, Distance.FromMiles(1)));
}

MainPage.xaml.cs (In UWP Solution)

public sealed partial class MainPage
{
    public MainPage()
    {
        this.InitializeComponent();
        Xamarin.FormsMaps.Init(Keys.UWPMapToken);
        Windows.Services.Maps.MapService.ServiceToken = Keys.UWPMapToken;
        LoadApplication(new Map_POC.App());
    }
}

Output: With hybrid map it shows map but not showing pin and locations properly.

enter image description here


  1. Other thing apart from this it not works in offline mode, can we cache map for offline mode?
  2. Can we draw a polygon and coordinates covered inside the polygon can be clicked individually or not?

Any help on this will be highly appreciated.

Divyesh
  • 2,085
  • 20
  • 35
  • If you build a non-Xamarin UWP app and use the UWP map control on this system, does the map load there? Another thing to try is launching the Windows map application which also uses the UWP map control. – Duncan Lawler Jan 07 '22 at 17:05
  • For your question on offline support: the map control will work offline if maps have been downloaded for offline use through the Windows settings. A UWP application can also call an API to download maps, but this isn't part of the Xamarin forms map API, just the UWP maps API. – Duncan Lawler Jan 07 '22 at 17:06
  • It means with Xamarin it's not possible? – Divyesh Jan 08 '22 at 02:48
  • Use [Windows.Services.Maps](https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/) in UWP project and use `custom-renderer` or dependency-service` to display in forms project . – ColeX Jan 10 '22 at 06:30
  • @ColeX-MSFT please can you share link of document or any sample that I can use for a reference? I have tried but I'm not getting anything related to it. – Divyesh Jan 10 '22 at 08:43
  • No link found, you can try to do that by yourself and ask here back if encountering any problem . – ColeX Jan 10 '22 at 09:14
  • The Xamarin code you posted above works fine for me when I build a Xamarin project locally, so there appears to be something odd with your system configuration. It's possible some firewall is blocking the network traffic the map control uses to download the map data – Duncan Lawler Jan 10 '22 at 17:59

0 Answers0