/// <summary> /// Method to set current map view to defined lat lon /// </summary> /// <param name="lat"></param> /// <param name="lon"></param> public void setPosition(double lat, double lon) { //parse lat lon to mapcontrol Location object Microsoft.Maps.MapControl.WPF.Location gpsPos = new Microsoft.Maps.MapControl.WPF.Location(lat, lon); //center map on position myMap.Center = gpsPos; //if first fix set zoom level - disable this for subsequent fixes. if (firstfix) { firstfix = false; myMap.ZoomLevel = 18; } //calculate locations of a circle of radius 5m around the current poitision var locations = GeoCodeCalc.CreateCircle(gpsPos, 0.005, DistanceMeasure.Kilometers); //set gps polygon (defined in XAML) Locations to the circle calculated above. gps.Locations = locations; }
/// <summary> /// Add point method. Used to add a single point to the map. /// </summary> /// <param name="lat"></param> /// <param name="lon"></param> /// <param name="alt"></param> public void addPoint(double lat, double lon, double alt) { //Point must be represented as circle 'polyon' //initiate polygon object MapPolygon point = new MapPolygon(); //convert lat lon doubles to Map control Location object. Microsoft.Maps.MapControl.WPF.Location pos = new Microsoft.Maps.MapControl.WPF.Location(lat, lon); //set polygon style point.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue); point.Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black); point.StrokeThickness = 1; point.Name = "point"; //use DataContext object to store point coordinates. point.DataContext = "[" + lon + "," + lat + "]"; //calculate circle verticies, radius of circle is 2.5m. Credit Chris Pietschmann see GeoCodeCalc.cs var locations = GeoCodeCalc.CreateCircle(pos, 0.0025, DistanceMeasure.Kilometers); point.Locations = locations; //add circle to map myMap.Children.Add(point); }