private async void GenerateGpx(LondonBicycles.Data.Models.Point myLocation, LondonBicycles.Data.Models.Point destination) { if (this.route.RoutePoints.Count() > 0) { XmlDocument doc = new XmlDocument(); XmlElement gpx = doc.CreateElement("gpx"); gpx.SetAttribute("xmlns", "http://www.topografix.com/GPX/1/1"); gpx.SetAttribute("version", "1.1"); gpx.SetAttribute("creator", "London Bicycles"); gpx.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); XmlElement wptStart = doc.CreateElement("wpt"); wptStart.SetAttribute("lon", myLocation.Longitude.ToString()); wptStart.SetAttribute("lat", myLocation.Latitude.ToString()); gpx.AppendChild(wptStart); XmlElement wptEnd = doc.CreateElement("wpt"); wptEnd.SetAttribute("lon", destination.Longitude.ToString()); wptEnd.SetAttribute("lat", destination.Latitude.ToString()); gpx.AppendChild(wptEnd); XmlElement track = doc.CreateElement("trk"); XmlElement trackSegment = doc.CreateElement("trkseg"); foreach (var point in this.route.RoutePoints) { XmlElement trackPoint = doc.CreateElement("trkpt"); XmlAttribute lonTrack = doc.CreateAttribute("lon"); lonTrack.Value = point.Longitude.ToString(); XmlAttribute latTrack = doc.CreateAttribute("lat"); latTrack.Value = point.Latitude.ToString(); trackPoint.SetAttribute("lon", point.Longitude.ToString()); trackPoint.SetAttribute("lat", point.Latitude.ToString()); trackSegment.AppendChild(trackPoint); } track.AppendChild(trackSegment); gpx.AppendChild(track); doc.AppendChild(gpx); string text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; text += doc.GetXml(); StorageFolder sf = Windows.Storage.ApplicationData.Current.RoamingFolder; StorageFile file = await sf.CreateFileAsync("route.gpx", CreationCollisionOption.ReplaceExisting); Windows.Storage.FileIO.WriteTextAsync(file, text); this.gpxFile = file; this.RegisterForShare(); } }
private void SetRouteOnMap(LondonBicycles.Data.Models.Point myLocation, LondonBicycles.Data.Models.Point destination) { LocationCollection wayPoints = new LocationCollection(); Bing.Maps.Location startWaypoint = new Bing.Maps.Location(myLocation.Latitude, myLocation.Longitude); Bing.Maps.Location endWaypoint = new Bing.Maps.Location(destination.Latitude, destination.Longitude); wayPoints.Add(startWaypoint); foreach (var routePoint in this.route.RoutePoints) { Bing.Maps.Location wayPoint = new Bing.Maps.Location() { Latitude = routePoint.Latitude, Longitude = routePoint.Longitude }; wayPoints.Add(wayPoint); } wayPoints.Add(endWaypoint); DrawRoute(wayPoints); DrawPin.SetMyLocationPin(startWaypoint, this.map); DrawPin.SetStationPin(endWaypoint, this.map); this.GenerateGpx(myLocation, destination); }