//using System; //using System.Net; //using System.Text; //using CoreLocation; //using Newtonsoft.Json.Linq; //using Shared; //using Shared.SimpleControl; //using UIKit; //namespace Location //{ // public class LocationManager // { // protected CLLocationManager locMgr; // public event EventHandler LocationUpdated = delegate { }; // public LocationManager () // { // this.locMgr = new CLLocationManager (); // this.locMgr.PausesLocationUpdatesAutomatically = false; // // iOS 8 has additional permissions requirements // if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) { // locMgr.RequestAlwaysAuthorization (); // works in background // //locMgr.RequestWhenInUseAuthorization (); // only in foreground // } // // iOS 9 requires the following for background location updates // // By default this is set to false and will not allow background updates // if (UIDevice.CurrentDevice.CheckSystemVersion (9, 0)) { // locMgr.AllowsBackgroundLocationUpdates = true; // } // LocationUpdated += PrintLocation; // } // public void sss () // { // //获取经纬度 // System.Threading.Tasks.Task.Run (() => { // while (true) { // System.Console.WriteLine ("Get Location GetAirQuality"); // try { // //获取天气 // var webClient = new WebClient (); // string url = $"https://developer.hdlcontrol.com/Weather/Weather/FindCity/?lon={locMgr.Location.Coordinate.Longitude}&lat={locMgr.Location.Coordinate.Latitude}"; // string responseString = null; // try { // responseString = Encoding.UTF8.GetString (webClient.DownloadData (url)); // } catch (Exception ex) { // Console.WriteLine (ex.Message); // } // if (responseString != null) { // try { // var revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject (responseString); // JObject jt = Newtonsoft.Json.JsonConvert.DeserializeObject (revertObj.ResponseData.ToString ()); // MainPage.city = jt ["City"].ToString (); // var cityId = jt ["Cid"].ToString (); // url = $"https://developer.hdlcontrol.com/Weather/Weather/GetAirQualityAndWeather/?cid={cityId}"; // responseString = null; // try { // responseString = Encoding.UTF8.GetString (webClient.DownloadData (url)); // revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject (responseString); // jt = Newtonsoft.Json.JsonConvert.DeserializeObject (revertObj.ResponseData.ToString ()); // MainPage.airQTemp = jt ["Temperature"].ToString (); // MainPage.airQHumidity = jt ["Humidity"].ToString (); // MainPage.airQAirPM25 = jt ["PM25"].ToString (); // MainPage.airQAirWeather = jt ["Weather"].ToString (); // } catch (Exception ex) { // Console.WriteLine (ex.Message); // } // } catch (Exception ex) { // Console.WriteLine (ex.ToString ()); // } // break; // } // } catch (Exception ex) { // Console.WriteLine (ex.Message); // } // System.Threading.Thread.Sleep (1000); // } // }); // } // public CLLocationManager LocMgr { // get { return this.locMgr; } // } // public void StartLocationUpdates () // { // // We need the user's permission for our app to use the GPS in iOS. This is done either by the user accepting // // the popover when the app is first launched, or by changing the permissions for the app in Settings // if (CLLocationManager.LocationServicesEnabled) { // //set the desired accuracy, in meters // LocMgr.DesiredAccuracy = 1; // LocMgr.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => { // // fire our custom Location Updated event // LocationUpdated (this, new LocationUpdatedEventArgs (e.Locations [e.Locations.Length - 1])); // }; // LocMgr.StartUpdatingLocation (); // } // } // //This will keep going in the background and the foreground // public void PrintLocation (object sender, LocationUpdatedEventArgs e) // { // CLLocation location = e.Location; // Console.WriteLine ("Altitude: " + location.Altitude + " meters"); // Console.WriteLine ("Longitude: " + location.Coordinate.Longitude); // Console.WriteLine ("Latitude: " + location.Coordinate.Latitude); // Console.WriteLine ("Course: " + location.Course); // Console.WriteLine ("Speed: " + location.Speed); // } // } //} //namespace Location //{ // public class LocationUpdatedEventArgs : EventArgs // { // CLLocation location; // public LocationUpdatedEventArgs (CLLocation location) // { // this.location = location; // } // public CLLocation Location { // get { return location; } // } // } //}