// Constructor public MainPage() { InitializeComponent(); _geolocator = new Geolocator(); MapCurrentLocation(); _locationIcon10m = new LocationIcon10m(); _locationIcon100m = new LocationIcon100m(); if (myTimer != null) { myTimer.Stop(); } if (trackerTimer != null) { trackerTimer.Stop(); } // Sample code to localize the ApplicationBar //BuildLocalizedApplicationBar(); }
void SetUserTrackCurrentLocation(double latitude, double longitude) { try { if (btnTrack.Content.Equals("➤")) { return; } foreach (var children in trvMap.Children) { if (children.GetType().Name == "LocationIcon10m") { trvMap.Children.Remove(children); break; } } // Get the cancellation token. _cts = new CancellationTokenSource(); token = _cts.Token; // Get the location. CloseMessage(); System.Device.Location.GeoCoordinate location = new System.Device.Location.GeoCoordinate(latitude, longitude); // Now set the zoom level of the map based on the accuracy of our location data. // Default to IP level accuracy. We only show the region at this level - No icon is displayed. double zoomLevel = 17.0f; LocationIcon10m _locationUserIcon10m = new LocationIcon10m(); Callout callout = new Callout(); callout.Text = "Tracker's Location"; callout.Lon = "Lon (λ): " + location.Longitude.ToString().Substring(0, 7);; callout.Lat = "Lat (φ): " + location.Latitude.ToString().Substring(0, 7);; _locationUserIcon10m.DataContext = callout; // Add the 10m icon and zoom closer. trvMap.Children.Add(_locationUserIcon10m); MapLayer.SetPosition(_locationUserIcon10m, location); // Set the map to the given location and zoom level. trvMap.SetView(location, zoomLevel); } catch { } }