private async void searchImage_Tapped(object sender, TappedRoutedEventArgs e)
{
if (!searchBox.Text.Equals(string.Empty) && searchBox.Text.Count() <= 4)
{
XDocument loaded = XDocument.Load("allStops.txt");
var stops = (from el in loaded.Elements("Buses").Descendants("Stop")
where (string)el.Attribute("Line") == searchBox.Text && (string)el.Attribute("Dir") == "1"
select el.Attribute("StopID").Value).ToList();
Stream stream;
string fileContent;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///stops.txt"));
using (StreamReader sRead = new StreamReader(await file.OpenStreamForReadAsync()))
{
fileContent = await sRead.ReadToEndAsync();
string[] stopsGeoData = fileContent.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
MapIcon mapIcon = new MapIcon();
foreach (string line in stopsGeoData)
{
if (stops.Contains(line.Split(',')[0]))
{
string lat = line.Split(',')[4];
string lon = line.Split(',')[5];
mapIcon = new MapIcon();
// Locate your MapIcon
mapIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/AppIcons/ATH_icons_bus_grey.png"));
// Show above the MapIcon
mapIcon.Title = line.Split(',')[2];
// Setting up MapIcon location
mapIcon.Location = new Geopoint(new BasicGeoposition()
{
Latitude = Convert.ToDouble(lat),
Longitude = Convert.ToDouble(lon)
});
// Positon of the MapIcon
mapIcon.NormalizedAnchorPoint = new Point(0.5, 0.5);
GeoData.MapElements.Add(mapIcon);
}
}
await GeoData.TrySetViewAsync(mapIcon.Location, 15d, 0, 0, MapAnimationKind.Bow);
}
}
}
}