Skip to content

Instantly share code, notes, and snippets.

@jflam
Created August 6, 2010 06:35
Show Gist options
  • Save jflam/510948 to your computer and use it in GitHub Desktop.
Save jflam/510948 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Media;
using System.Xml.Linq;
using Microsoft.Maps.MapControl;
namespace Map
{
public partial class MainPage : UserControl
{
private LocationCollection ReadTcxFile(string url)
{
XNamespace g = "http://www.topografix.com/GPX/1/1";
XDocument root = XDocument.Load(url);
var trkpts = root.Element(g + "gpx").Element(g + "trk").Element(g + "trkseg").Elements(g + "trkpt");
var pts = from trkpt in trkpts
select new {
lat = Convert.ToDouble((string)trkpt.Attribute("lat")),
lon = Convert.ToDouble((string)trkpt.Attribute("lon")),
};
var result = new LocationCollection();
foreach (var pt in pts)
{
result.Add(new Location(pt.lat, pt.lon));
}
return result;
}
public MainPage()
{
InitializeComponent();
MyMap.Mode = new RoadMode();
var line = new MapPolyline();
line.Stroke = new SolidColorBrush(Colors.Blue);
line.StrokeThickness = 5;
line.Opacity = 0.5;
line.Locations = ReadTcxFile("ride.gpx");
MyMap.Center = line.Locations[0];
MyMap.ZoomLevel = 14;
MyMap.Children.Add(line);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment