/// <summary> /// Positions current location indicator on map /// </summary> /// <param name="pin">Current location pin object</param> /// <param name="position">Coordinate at which to place pin</param> public static void SetCurrentLocationPin(this Map m, CurrentLocationPin pin, GeoCoordinate position) { MapOverlay locationOverlay = default(MapOverlay); // find first layer that includes a CurrentLocationPin var locationLayer = m.Layers.Where(l => l.Where(o => o.Content.GetType() == pin.GetType()).Count() > 0).FirstOrDefault(); // if there's not an overlay for current location, create it if (locationLayer == null) { // create an overlay locationOverlay = new MapOverlay(); locationOverlay.Content = pin; locationOverlay.PositionOrigin = pin.AnchorPoint; // create a layer and and add overlay to it locationLayer = new MapLayer(); locationLayer.Add(locationOverlay); // add layer to the map m.Layers.Add(locationLayer); } // update the position and visibility of the current location pin if (locationOverlay != null) { locationOverlay.GeoCoordinate = position; pin.Visibility = Visibility.Visible; } }