Before reading this article, I highly recommend reading the previous part:
Introduction
We continue our path with geolocation services, but making a guide to what we saw in the previous article on the control Nokia Maps. We analyzed the main functions, starting from the property ZoomLevel, able to change proportionally viewing the content on the map, then all the display types are available, from the Aerial Terrain. We saw other properties to provide more customization to the map, starting from the heading with which you can rotate the map of the center, ending with PedestrianFeaturesEnabled suitable when we walk. Finally was a brief introduction to what levels are, in other words the ability to create and superimpose the map of the custom layer, so as to display one or more points of interest, the whole with the class MapOverlay. This article will show how to insert one or more placeholders on the map, we will see that in the order:
- Placeholder generic
- Installing the Phone Toolkit
- Using the generic placeholder
- Test the generic placeholder
- Inserting more placeholder
- Test multiple placeholders
- Using the placeholder UserLocationMarker
- Test the control UserLocationMarker
- Conclusion
Remember to use the services of geolocation and maps; you must enable the capability ID_CAP_LOCATION and ID_CAP_MAP, discussed in previous articles found in the file WMAppManifest.xml (the features section).
Placeholder generic
As seen in the previous article, it is possible, by means of a layer, to customize the map view so the points of interest of our present position, all thanks to geolocation services. However, there are other ways to do this, the placeholder. There are two types, generic ones that will handle it in a short amount of code and those called UserLocationMarker. It is good to know that the SDK for Windows Phone 8 does not have these controls, you need to add them to the project with a reference to the Phone Toolkit for Windows Phone. The Phone Toolkit provides developers a series of controls, including an element called a pushpin. This control is what we will use to view our location on the map control. Nokia Maps offers various scenarios that we can implement within our application, a classic example is to calculate a route displayed on the map, but we see the main features in addition to the one just described.
Installing the Phone Toolkit
If available, we take over the project previously created with Visual Studio 2013, for those who have not had the opportunity to read the previous article, I leave the link to download the sample source code. We start Visual Studio 2013, the "File" menu select "Open" and immediately after "Project / Solution." For those who have downloaded the project from the preceding link, you go to select the file, depending on where you put it after you extracted the contents of the Zip file. Once you have opened the project, "explores solutions" we place the cursor on the "References", right-click and choose the command "Manage Nuget packages". We will use Nuget to install and add in the references of our project, the Windows Phone Toolkit. In the dialog that follows, we write Windows Phone Toolkit.
Image 1.1 The Phone Toolkit on Nuget.
After finding the library and clicking on the "Install" button, if all goes well, as shown in the figure, a green circle with a check mark in it means that it has been installed properly. We installed all you need; we look at what was added after installation of the Phone Toolkit.
Image 1.2 The Phone Toolkit in the references after installation.
We note that we have a new reference for our project: Microsoft.Phone.Controls.Toolkit. Let us examine the placeholders as anticipated previously available.
Using the generic placeholder
Let's go back to our project, we place the cursor on "GeoPositionSample", right-click, choose the command "Add", after "New Item", and choose the template "page vertical Windows Phone", as shown in the figure and call it PushPinSample.
Image 1.3 The Add new item screen.
We insert the following code, to define the graphical interface. Before namespaces.
- xmlns:Controls="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
- x:Class="GeoPositionSample.PushPinSample"
- <!--LayoutRoot è la griglia radice in cui viene inserito tutto il contenuto della pagina-->
- <Grid x:Name="LayoutRoot" Background="Transparent">
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
- <!--TitlePanel contiene il nome dell'applicazione e il titolo della pagina-->
- <StackPanel Grid.Row="0" Margin="12,17,0,28">
- <TextBlock Text="GeoPositionSample" Style="{StaticResource PhoneTextNormalStyle}"/>
- <TextBlock Text="PushPin sample" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
- </StackPanel>
- <!--ContentPanel - inserire ulteriore contenuto qui-->
- <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
- <Grid.RowDefinitions>
- <RowDefinition Height="*"/>
- <RowDefinition Height="Auto"/>
- </Grid.RowDefinitions>
- <StackPanel>
- <Controls:Map x:Name="mapLocation" Height="442" Width="480">
- <toolkit:MapExtensions.Children>
- <toolkit:Pushpin x:Name="myPushPin" Content="your position" Visibility="Collapsed"/>
- </toolkit:MapExtensions.Children>
- </Controls:Map>
- </StackPanel>
- <Button Grid.Row="1" x:Name="btnFindCoordinate" Content="Find data" Tap="btnFindCoordinate_Tap"/>
- </Grid>
- </Grid>

Image 1.4 The screen layout PushPinSample.
Defined graphical interface, we can handle everything you need for the inclusion of the generic placeholder. The first thing to do is to add the required namespace in file.xaml class pushpin.
- xmlns:toolkit="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit"
- <Controls:Map x:Name="mapLocation" Height="442" Width="480">
- <toolkit:MapExtensions.Children>
- <toolkit:Pushpin x:Name="myPushPin"/>
- </toolkit:MapExtensions.Children>
- </Controls:Map>
- public static async void MyPushPinPosition(Map maps)
- {
- var latitude = 0d;
- var longitude = 0d;
- try
- {
- var locator = new Geolocator();
- if (!locator.LocationStatus.Equals(PositionStatus.Disabled))
- {
- var position = await locator.GetGeopositionAsync();
- latitude = position.Coordinate.Latitude;
- longitude = position.Coordinate.Longitude;
- var pushpin = (Pushpin) maps.FindName("myPushPin");
- pushpin.GeoCoordinate = new GeoCoordinate(latitude, longitude);
- pushpin.Visibility = System.Windows.Visibility.Visible;
- maps.ZoomLevel = 19;
- maps.Center = new GeoCoordinate(latitude, longitude);
- }
- else
- {
- MessageBox.Show("Service Geolocation not enabled!", AppResources.ApplicationTitle, MessageBoxButton.OK);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- if (!locator.LocationStatus.Equals(PositionStatus.Disabled))
- var pushpin = (Pushpin) maps.FindName("myPushPin");
- pushpin.GeoCoordinate = new GeoCoordinate(latitude, longitude);
- pushpin.Visibility = System.Windows.Visibility.Visible;
- <Button x:Name="btnPushPinSample" Content="PushPinSample" Tap="btnPushPinSample_Tap"/>

Image 1.5 The screen layout MainPage.
The last thing to do is to manage the navigation from MainPage to PushPinSample, we execute it using the Navigate method () of the property NavigationService belonging to the namespace System.Windows.Navigation. Open the file MainPage.xaml.cs and insert the following code.
- private void btnPushPinSample_Tap(object sender, System.Windows.Input.GestureEventArgs e)
- {
- NavigationService.Navigate(new Uri("/PushPinSample.xaml", UriKind.Relative));
- }

Image 1.6 The new home screen.
We note that we have the new button PushPinSample. We do a tap on it and we will be led into the new screen that we designed before.

Image 1.7 The screen image PushPinSample.
We have a Map control and a Button called Maps Find position. Now let's do a tap on the button and if everything is done correctly, this is the result of research position.

Image 1.8 The screen image PushPinSample after location research performed.
Inserting more placeholder
In this short procedure, it is seen as creating a placeholder, detect using geolocation services the user's location, the property value of the control GeoCoordinate pushpin and then show it on the map. However, there are cases where you need to specify multiple points of interest, as if we execute the download from a service on which we have more latitude and longitude coordinates to manage. The most suitable solution in this case, is to create the controls pushpin directly from code. Suppose you want to display a number of hotels in a specific area. We will create the first class, where we will gather all the necessary information. Let's go back to the project, we place the cursor on the project name in the Solution Explorer, right-click and select the command "Add" and immediately after "Class". We assign the name "Hotel" to the newly created class, after we replace the code with this.
- using System.Device.Location;
- namespace GeoPositionSample
- {
- class Hotel
- {
- public GeoCoordinate Coordinate { get; set; }
- public string NameHotel { get; set; }
- }
- }

Image 1.9 The Add new item screen.
Remaining in the XAML file, insert the following code to define the graphics, starting with the namespace needed, to use the map and controls Phone Toolkit.
- xmlns:Controls="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
- xmlns:toolkit="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit"
- <!--LayoutRoot è la griglia radice in cui viene inserito tutto il contenuto della pagina-->
- <Grid x:Name="LayoutRoot" Background="Transparent">
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
- <!--TitlePanel contiene il nome dell'applicazione e il titolo della pagina-->
- <StackPanel Grid.Row="0" Margin="12,17,0,28">
- <TextBlock Text="GeoPositionSample" Style="{StaticResource PhoneTextNormalStyle}"/>
- <TextBlock Text="MultiplePushPin" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
- </StackPanel>
- <!--ContentPanel - inserire ulteriore contenuto qui-->
- <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
- <Grid.RowDefinitions>
- <RowDefinition Height="*"/>
- <RowDefinition Height="Auto"/>
- </Grid.RowDefinitions>
- <StackPanel>
- <Controls:Map x:Name="mapLocation" Height="442" Width="480">
- <toolkit:MapExtensions.Children>
- <toolkit:MapItemsControl>
- <toolkit:MapItemsControl.ItemTemplate>
- <DataTemplate>
- <toolkit:Pushpin
- x:Name="myPushPin"
- Content="{Binding NameHotel}"
- GeoCoordinate="{Binding Coordinate}"/>
- </DataTemplate>
- </toolkit:MapItemsControl.ItemTemplate>
- </toolkit:MapItemsControl>
- </toolkit:MapExtensions.Children>
- </Controls:Map>
- </StackPanel>
- <Button Grid.Row="1" x:Name="btnFindCoordinate" Content="Find Hotel" Tap="btnFindCoordinate_Tap"/>
- </Grid>
- </Grid>
- <toolkit:MapItemsControl>
- <toolkit:MapItemsControl.ItemTemplate>
- <DataTemplate>
- <toolkit:Pushpin
- x:Name="myPushPin"
- Content="{Binding NameHotel}"
- GeoCoordinate="{Binding Coordinate}"/>
- </DataTemplate>
- </toolkit:MapItemsControl.ItemTemplate>
- </toolkit:MapItemsControl>

Image 1.10 The new screen MultiplePushPin.
After the part about the graphics, with the F7 key pass code editor. We will need to first add the namespace necessary to use all the functionality required.
- using Microsoft.Phone.Maps.Toolkit;
- using System.Collections.ObjectModel;
- using System.Device.Location;
- using System.Linq;
- using System.Windows;
- using Microsoft.Phone.Controls;
- using Microsoft.Phone.Maps.Toolkit;
- using System.Collections.ObjectModel;
- using System.Device.Location;
- namespace GeoPositionSample
- {
- public partial class MultiplePushPin : PhoneApplicationPage
- {
- ObservableCollection<Hotel> Hotels = new ObservableCollection<Hotel>();
- public MultiplePushPin()
- {
- InitializeComponent();
- }
- private void btnFindCoordinate_Tap(object sender, System.Windows.Input.GestureEventArgs e)
- {
- Hotels.Add( new Hotel { Coordinate = new GeoCoordinate(45.07146, 7.68349), NameHotel = "Town House 70" });
- Hotels.Add( new Hotel { Coordinate = new GeoCoordinate(45.07257, 7.68411), NameHotel = "Hotel Chelsea" });
- Hotels.Add( new Hotel { Coordinate = new GeoCoordinate(45.07107, 7.68062), NameHotel = "Hotel Azalea" });
- Hotels.Add( new Hotel { Coordinate = new GeoCoordinate(45.06777, 7.68317), NameHotel = "Hotel San Carlo"});
- Hotels.Add( new Hotel { Coordinate = new GeoCoordinate(45.06714, 7.68516), NameHotel = "Hotel MioMay" });
- ObservableCollection<DependencyObject> hotels = MapExtensions.GetChildren(mapLocation);
- var result = hotels.FirstOrDefault(w => w.GetType().Equals(typeof(MapItemsControl))) as MapItemsControl;
- var midLatitude = Hotels.Average(a => a.Coordinate.Latitude);
- var midLongitude = Hotels.Average(b => b.Coordinate.Longitude);
- result.ItemsSource = Hotels;
- mapLocation.ZoomLevel = 16;
- mapLocation.Center = new GeoCoordinate(midLatitude, midLongitude);
- }
- }
- }
- ObservableCollection<DependencyObject> hotels = MapExtensions.GetChildren(mapLocation);
- var result = hotels.FirstOrDefault(w => w.GetType().Equals(typeof(MapItemsControl))) as MapItemsControl;
- var midLatitude = Hotels.Average(a => a.Coordinate.Latitude);
- var midLongitude = Hotels.Average(b => b.Coordinate.Longitude);
- result.ItemsSource = Hotels;
- mapLocation.ZoomLevel = 16;
- mapLocation.Center = new GeoCoordinate(midLatitude, midLongitude);
- mapLocation.Center = new GeoCoordinate(midLatitude, midLongitude);
- <Button x:Name="btnMultiplePushPin" Content="Multiple push pin" Tap="btnMultiplePushPin_Tap"/>
- private void btnMultiplePushPin_Tap(object sender, System.Windows.Input.GestureEventArgs e)
- {
- NavigationService.Navigate(new Uri("/MultiplePushPin.xaml", UriKind.Relative));
- }

Image 1.11 new screens MainPage.
We can now test the application, F5 and start the debugging, we do a tap on the button Multiple push pin, entered the new screen, another tap on the button Find Hotel, if all goes well, this is how the map will look at the end of the search.

Image 1.12 map to search performed.
Using the placeholder UserLocationMarker
In some cases, the control pushpin is not ideal to report the location of the user, especially when moving. The Phone toolkit provides another placeholder, called UserLocationMarker. The management of this placeholder is nearly identical to the generic one. As we will see the changes to be made are really minimal. Let's go back to the project and open the file PushPinSample.xaml and modify the existing code
- <StackPanel>
- <Controls:Map x:Name="mapLocation" Height="442" Width="480">
- <toolkit:MapExtensions.Children>
- <toolkit:Pushpin x:Name="myPushPin" Content="your position" Visibility="Collapsed"/>
- </toolkit:MapExtensions.Children>
- </Controls:Map>
- </StackPanel>
- <StackPanel>
- <Controls:Map x:Name="mapLocation" Height="442" Width="480">
- <toolkit:MapExtensions.Children>
- <toolkit:UserLocationMarker x:Name="myUserLocationMarker" Visibility="Collapsed"/>
- </toolkit:MapExtensions.Children>
- </Controls:Map>
- </StackPanel>
- var pushpin = (Pushpin)maps.FindName("myPushPin");
- pushpin.GeoCoordinate = new GeoCoordinate(latitude, longitude);
- pushpin.Visibility = System.Windows.Visibility.Visible;
- var userLocationMarker = (UserLocationMarker)maps.FindName("myUserLocationMarker");
- userLocationMarker.GeoCoordinate = new GeoCoordinate(latitude, longitude);
- userLocationMarker.Visibility = Visibility.Visible;
Test control UserLocationMarker
Perform these changes, we can again start debugging the application by pressing F5, MainPage screen, tap on the button PushPinSample and then tap on the Find button position. If everything was done correctly, this is how you present the map with the new control.

Image 1.13 The map control UserLocationMarker.
Conclusion
This article, it was explained what are placeholders, how to define, create and then superimpose the control NokiaMaps, but starting from the installation of Phone Toolkit, need to be able to make use. Later, with the control pushpin, was defined as display the user's location and for the signaling of multiple points of interest. Finally, we made a brief overview of what is control UserLocationMarker, also part of Phone Toolkit. In the next article, we will see how you can view a route on the map and how to calculate a route.

Join the conversation! Your thoughts help the community grow.