Example #1
0
        private async void OnTimedHttpCallEvent(object sender, ElapsedEventArgs e)
        {
            //Remove RETURN statement when API endpoint is ready
            return;

            if (LatLonCollection.Any())
            {
                await HttpCall.CallNetwork(LatLonCollection[0]);
            }
        }
Example #2
0
        private void OnTimedGetLocationEvent(object sender, ElapsedEventArgs e)
        {
            try
            {
                Device.BeginInvokeOnMainThread(async() =>
                {
                    var request  = new GeolocationRequest(GeolocationAccuracy.Medium);
                    var location = await Geolocation.GetLocationAsync(request);

                    if (location != null)
                    {
                        LatLonCollection.Insert(0, new LatLon {
                            Latitude = location.Latitude.ToString(), Longitude = location.Longitude.ToString()
                        });
                        //Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
                        string loca = Newtonsoft.Json.JsonConvert.SerializeObject(new
                        {
                            uid       = id,
                            latitude  = location.Latitude,
                            longitude = location.Longitude,
                        });
                        var content = new StringContent(loca, Encoding.UTF8, "application/json");


                        var response = await client.PostAsync("https://162.236.218.100:5005//gpsdata", content);
                        var result   = response.Content.ReadAsStringAsync().Result;

                        Debug.WriteLine("Neku for smash" + result);
                    }
                });
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                // Handle not supported on device exception
                Console.WriteLine(fnsEx.Message);
            }
            catch (FeatureNotEnabledException fneEx)
            {
                // Handle not enabled on device exception
                Console.WriteLine(fneEx.Message);
            }
            catch (PermissionException pEx)
            {
                // Handle permission exception
                Console.WriteLine(pEx.Message);
            }
            catch (Exception ex)
            {
                // Unable to get location
                Console.WriteLine(ex.Message);
            }
        }