| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 | using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Xamarin.Forms;using Xamarin.Forms.Maps;using InABox.Core;using Comal.Classes;using XF.Material.Forms.UI.Dialogs;namespace comal.timesheets{    public class GPSJobModel    {        public String JobNumber { get; set; }        public String JobName { get; set; }        public double Distance { get; set; }    }    public partial class GPSInfoPage : ContentPage    {        Location _here = null;        CoreTable _jobs = null;        public void GetLocation(double latitude, double longitude)        {            Task.Run(async () =>            {                String address = "";                var coder = new Geocoder();                var location = await coder.GetAddressesForPositionAsync(new Xamarin.Forms.Maps.Position(latitude, longitude));                if (location.Any())                    address = location.First();                Device.BeginInvokeOnMainThread(() => { Location.Text = address; });            });        }        public GPSInfoPage(CoreTable jobs)        {            _here = new Location() { Latitude = App.GPS.Latitude, Longitude = App.GPS.Longitude };            _jobs = jobs;            InitializeComponent();            NavigationPage.SetHasBackButton(this, false);            ToolbarItems.Clear();            ToolbarItems.Add(new ToolbarItem("Back", "", () =>            {                Navigation.PopAsync();            }));            Title = "GPS Info";            GetLocation(App.GPS.Latitude, App.GPS.Longitude);            TimeStamp.Text = String.Format("{0:dd/MM/yy hh:mm:ss tt}", App.GPS.TimeStamp);        }        protected override async void OnAppearing()        {            base.OnAppearing();            await LoadData();        }        private async Task LoadData()        {            using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading Data"))            {                                List<GPSJobModel> jobmodel = new List<GPSJobModel>();                if (_jobs != null)                {                    foreach (CoreRow row in _jobs.Rows)                    {                        Location job = new Location()                        {                            Latitude = row.Get<Job, double>(x => x.SiteAddress.Location.Latitude),                            Longitude = row.Get<Job, double>(x => x.SiteAddress.Location.Longitude),                        };                        if ((job.Latitude != 0.0F) && (job.Longitude != 0.0F))                        {                            jobmodel.Add(                                new GPSJobModel()                                {                                    JobNumber = row.Get<Job, String>(x => x.JobNumber),                                    JobName = row.Get<Job, String>(x => x.Name),                                    Distance = _here.DistanceTo(job, UnitOfLength.Kilometers),                                }                            );                        }                    }                }                Device.BeginInvokeOnMainThread(                    () =>                    {                        JobList.ItemsSource = null;                        JobList.ItemsSource = jobmodel;                    }                );            }        }    }}
 |