JLChen
2020-04-15 19545253f1977af3ef84b301183c2e12107983c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//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<LocationUpdatedEventArgs> 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<ResponsePack> (responseString);
//                                JObject jt = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject> (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<ResponsePack> (responseString);
//                                    jt = Newtonsoft.Json.JsonConvert.DeserializeObject<JObject> (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; }
//        }
//    }
//}