In this article I will talk about MapDownloaderTask, MapsTask and MapsDirectionsTask in Windows Phone.
MapsDownloadTask allows user to download map data for offline use.
MapsTask allows to find matching locations specified in search criteria on map.
MapsDirectionsTask allows user to get the direction from starting location to ending location.
Step 1: Create three buttons in the MainPage.xaml. First button (btnMapsDownloader) will be used to download the Map data for offline use. Second button (btnMaps) will be used to find matching location specified in search criteria on map. Third button (btnMapsDirections) will be used to find the direction from starting location to ending location.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Height="100" x:Name="btnMapsDownloader" Content="Maps Downloader" Click="btnMapsDownloader_Click_1"></Button>
<Button Height="100" Margin="0,200,0,0" x:Name="btnMaps" Content="Maps" Click="btnMaps_Click_1"></Button>
<Button Height="100" Margin="0,400,0,0" x:Name="btnMapsDirections" Content="Maps Directions" Click="btnMapsDirections_Click_1"></Button>
Step 2: Add Microsoft.Phone.Tasks
Step 3: Add btnMapsDownloader_Click_1 event handler which will be invoked on click of btnMapsDownloader button.
MapDownloaderTask has only one method which is Show to show the map settings application.
private void btnMapsDownloader_Click_1(object sender, RoutedEventArgs e)
MapDownloaderTask mapDownloaderTask = new MapDownloaderTask();
Step 4: Add System.Device.Location.
Step 5: Add btnMaps_Click_1 event which will be triggered on click of btnMaps button.
MapsTask has again only one method Show which opens the map application. There are three properties, Center, SearchItem and ZoomLevel.
Center property gets or sets the location which will be used as the center point for the map.
SearchTerm gets or sets the search term which is used to find and tag locations on Map.
ZoomLevel sets the initial zoom level of Map.
private void btnMaps_Click_1(object sender, RoutedEventArgs e)
MapsTask mapsTask = new MapsTask();
//Omit the Center property to use the user's current location.
mapsTask.Center = new GeoCoordinate(-37.6204, -32.3493);
mapsTask.SearchTerm = "fire brigade";
mapsTask.ZoomLevel = 2;
The minimum value of latitude is -90 and maximum value of latitude is 90.
The minimum value of longitude is -180 and maximum value of longitude is 180.
System.ArgumentOutOfRangeException will be thrown in case the value specified in latitude and longitude is outside minimum and maximum range.
Step 6: Add btnMapsDirections_Click_1 event which will be triggered on click of btnMapsDirections button.
MapsDirectionsTask has only one method Show which will open the maps application with driving direction displayed for the specified start and end point.
Start property specifies the starting location of driving.
End property specifies the end location of driving.
private void btnMapsDirections_Click_1(object sender, RoutedEventArgs e)
MapsDirectionsTask mapsDirectionsTask = new MapsDirectionsTask();
//GeoCoordinate spaceNeedleLocation = new GeoCoordinate(-37.6204, -322.3493);
// If you set the geocoordinate parameter to null, the label parameter is used as a search term.
LabeledMapLocation startLocation = new LabeledMapLocation("Microsoft Building 1", null);
LabeledMapLocation endLocation = new LabeledMapLocation("Microsoft Building 10", null);
// If mapsDirectionsTask.Start is not set, the user's current location is used as the start point.
mapsDirectionsTask.Start = startLocation;
mapsDirectionsTask.End = endLocation;
Step 7: Now run the application.
i) On Click or touch first button (Maps Downloader) below screen will appear to download maps.
ii) On Click or touch of Add button in application you will get below screen to choose a continent.
iii) Select continent as Asia from the above screen, on selection of Asia you will get all the countries of Asia.
iv) Select India from above screen and you will get all the regions of India as shown in the below screenshot.
v) On click of any of the region from you will get screen like below with button Download.
vi) On click of Download button the Map will start downloading for offline use as shown in below screenshot.
i) On Click or touch second button (Maps), user will get prompter for permission to access the user location. Click Allow button.
ii) On click of allow button you will get screen like below where the search item keyword will be mapped on map.
On click or touch of third button (Maps Directions) below screen will appear with direction from start location to end location.
This ends the article of MapDownloaderTask, MapsTask and MapsDirectionsTask in Windows Phone,