Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Phone 8 - HowTo display current position on the map
    primarykey
    data
    text
    <p>As the title suggest I am struggeling with the display of the current location of the user on the map. </p> <p>Afaik there a two ways to display the current user location:</p> <ol> <li><p>In Code: create a ellipse, set it as content of a <code>MapOverlay</code>, set the GeoCoordinate of the MapOverlay, add this overlay to a <code>MapLayer</code> and add this to the map - but I cannot access the <code>MapOverlay</code> anymore and thus I cannot change (update) the position of the user. <strong>Is there a way to update the user position without having to redraw all the map layers?</strong></p></li> <li><p>XAML and Code: In Windows Phone 7 I was able to add a <code>Pushpin</code> to the map and let the <code>GeoCoordinateWatcher</code> handle the <code>PositionChanged</code> event and set the <code>MyLocation.Location</code> to the current location.</p></li> </ol> <p>It seems that there is no way to add a <code>Pushpin</code> to the map if you don't use the Windows Phone Toolkit. So I tried to add <code>Pushpin</code> from the Windows Phone Toolkit:</p> <pre class="lang-xml prettyprint-override"><code>xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps" xmlns:maptk="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit" &lt;maptk:Pushpin x:Name="MyLocation"&gt; &lt;maptk:Pushpin.Template&gt; &lt;ControlTemplate&gt; &lt;Ellipse Width="15" Height="15" Margin="0" Fill="SteelBlue" StrokeThickness="1" Stroke="Black"/&gt; &lt;/ControlTemplate&gt; &lt;/maptk:Pushpin.Template&gt; &lt;/maptk:Pushpin&gt; </code></pre> <p>But I cannot access the MyLocation pushpin in my MapPage.xaml (the debugger says it is <code>null</code>).</p> <p><strong>Can I display and update the current user position on the map with <code>maptk:Pushpin</code>?</strong></p> <p>In Windows Phone 7 I could simply create a XAML layout for the pushpin which would hold the user location like this:</p> <pre class="lang-xml prettyprint-override"><code>xmlns:maps="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps" &lt;maps:Map Grid.Row="2" x:Name="Map" &gt; &lt;maps:Pushpin x:Name="MyLocation" &gt; &lt;maps:Pushpin.Template&gt; &lt;ControlTemplate&gt; &lt;Ellipse Width="12" Height="12" Margin="0" Fill="SteelBlue" StrokeThickness="1" Stroke="Black" /&gt; &lt;/ControlTemplate&gt; &lt;/maps:Pushpin.Template&gt; &lt;/maps:Pushpin&gt; &lt;/maps:Map&gt; </code></pre> <p>then I could add a <code>GeoCoordinateWatcher</code> which would listen for the <code>PositionChanged</code> event and change the <code>Location</code> of the MyLocation pushpin:</p> <pre class="lang-cs prettyprint-override"><code>void GeoCoordinateWatcher_PositionChanged ( object sender, GeoPositionChangedEventArgs&lt;GeoCoordinate&gt; e ) { MyLocation.Location = e.Position.Location; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload