Display maps and use locators to enable search and routing offline using a Mobile Map Package.
Use case
Mobile map packages make it easy to transmit and store the necessary components for an offline map experience including: transportation networks (for routing/navigation), locators (address search, forward and reverse geocoding), and maps.
A field worker might download a mobile map package to support their operations while working offline.
How to use the sample
A list of maps from a mobile map package will be displayed. If the map contains transportation networks, the list item will have a navigation icon. Tap on a map in the list to open it. If a locator task is available, tap on the map to reverse geocode the location's address. If transportation networks are available, a route will be calculated between geocode locations.
How it works
- Create a
MobileMapPackage
usingMobileMapPackage.OpenAsync(path)
. - Get a list of maps using the
Maps
property. - If the package has a locator, access it using the
LocatorTask
property. - To see if a map contains transportation networks, check each map's
TransportationNetworks
property.
Relevant API
- GeocodeResult
- MobileMapPackage
- ReverseGeocodeParameters
- Route
- RouteParameters
- RouteResult
- RouteTask
- TransportationNetworkDataset
Offline data
This sample uses the San Francisco mobile map package.
Tags
disconnected, field mobility, geocode, network, network analysis, offline, routing, search, transportation
Sample Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntimeXamarin.Samples.MobileMapSearchAndRoute.MobileMapSearchAndRoute"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:converters="clr-namespace:ArcGISRuntimeXamarin.Converters;assembly=ArcGISRuntime"
xmlns:converters1="clr-namespace:Forms.Converters"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms"
xmlns:mapping="clr-namespace:Esri.ArcGISRuntime.Mapping;assembly=Esri.ArcGISRuntime"
xmlns:resources="clr-namespace:Forms.Resources;assembly=ArcGISRuntime">
<ContentPage.Resources>
<converters:NullOrEmptyToVisibilityConverter x:Key="NullToVisibilityConverter" />
<converters1:ItemToImageSourceConverter x:Key="ItemToImageSourceConverter" />
</ContentPage.Resources>
<RelativeLayout>
<esriUI:MapView x:Name="MyMapView"
BindingContext="{x:Reference Name=ResponsiveFormContainer}"
Style="{StaticResource MapWithFormStyle}" />
<resources:ResponsiveFormContainer x:Name="ResponsiveFormContainer">
<StackLayout>
<Label LineBreakMode="WordWrap" Text="Select a map from the package. If a network is available, you can route between tapped points. If a locator is available, the address for each tapped point will be displayed in a callout." />
<ListView x:Name="MapListView"
Margin="0,5,0,0"
HeightRequest="150"
ItemSelected="Map_Selected"
RowHeight="50">
<ListView.ItemTemplate>
<DataTemplate x:DataType="mapping:Map">
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding Item, Converter={StaticResource ItemToImageSourceConverter}}" />
<Image Grid.Column="1"
Margin="5"
HeightRequest="25"
IsVisible="{Binding TransportationNetworks, Converter={StaticResource NullToVisibilityConverter}}"
Source="{resources:ImageResource ArcGISRuntime.Resources.routingSymbol.png}"
WidthRequest="25" />
<Label Grid.Column="2"
HorizontalTextAlignment="Start"
Text="{Binding Item.Title}"
VerticalTextAlignment="Center" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</resources:ResponsiveFormContainer>
</RelativeLayout>
</ContentPage>