void HandleElapsed(object sender, ElapsedEventArgs e) { //1 create new DataPoint - lat, lon, datetime double saveUserLat; double saveUserLon; saveUserLat = locationManager.Location.Coordinate.Latitude; saveUserLon = locationManager.Location.Coordinate.Longitude; //2 add new DataPoint to LocationHistroy LocationDataPoint aDataPoint; aDataPoint = new LocationDataPoint() { Latitude = saveUserLat, Longitude = saveUserLon, aDateTime = DateTime.Now }; locationHistory.Add(aDataPoint); Console.WriteLine("Time {0}, Lat {1}, Lon {2}", aDataPoint.aDateTime, aDataPoint.Latitude, aDataPoint.Longitude); //3 store it DataAccess.DoSomeDataAccess(aDataPoint); //4 put up to Azure }
// public static string DoSomeDataAccess (LocationDataPoint inputDataPoint) public static void DoSomeDataAccess(LocationDataPoint inputDataPoint) { Console.WriteLine("DataAccess worked!"); var output = ""; output += "\nCreating database, if it doesn't already exist"; string dbPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.Personal), "XamarinMapsLocation.db3"); var db = new SQLiteConnection(dbPath); db.CreateTable <LocationDataPoint> (); // this will probably mess things up db.Insert(inputDataPoint); if (db.Table <LocationDataPoint> ().Count() == 0) { // only insert the data if it doesn't already exist // var newStock = new Stock (); // newStock.Symbol = "AAPL"; // db.Insert (newStock); // // newStock = new Stock (); // newStock.Symbol = "GOOG"; // db.Insert (newStock); // // newStock = new Stock (); // newStock.Symbol = "MSFT"; // db.Insert (newStock); } output += "\nReading data using Orm"; var table = db.Table <LocationDataPoint> (); foreach (var s in table) { output += "\n" + s.Id + " " + s.Latitude + s.Longitude; Console.WriteLine("Stored Time {0}, Lat {1}, Lon {2}", s.aDateTime, s.Latitude, s.Longitude); } // return output; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. map = new MKMapView(UIScreen.MainScreen.Bounds); map.MapType = MKMapType.Standard; locationManager = new CLLocationManager(); locationManager.RequestWhenInUseAuthorization(); locationManager.RequestAlwaysAuthorization(); //locationManager.StartUpdatingLocation (); map.ShowsUserLocation = true; this.View = map; double userLat; double userLon; //QUESTION - how do I get the user's latitude? // userLat = map.UserLocation.Coordinate.Latitude; locationManager.StartUpdatingLocation(); //userLat = 42.374260; //userLon = -71.120824; userLat = locationManager.Location.Coordinate.Latitude; ////QUESTION - how do I get the user's longitute? // userLon = map.UserLocation.Coordinate.Longitude; userLon = locationManager.Location.Coordinate.Longitude; // userLon = map.UserLocation.Coordinate.Longitude; // //-20150130 - let's center the view // double lat = 42.374260; // double lon = -71.120824; // var mapCenter = new CLLocationCoordinate2D (lat, lon); var mapCenter = new CLLocationCoordinate2D(userLat, userLon); var mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 2000, 2000); map.CenterCoordinate = mapCenter; map.Region = mapRegion; //store that location into the List<LocationDataPoint> locationHistory; LocationDataPoint aDataPoint; aDataPoint = new LocationDataPoint() { Latitude = userLat, Longitude = userLon, aDateTime = DateTime.Now }; locationHistory.Add(aDataPoint); Console.WriteLine("Time {0}, Lat {1}, Lon {2}", aDataPoint.aDateTime, aDataPoint.Latitude, aDataPoint.Longitude); //-20150130 - let's center the view // var mapCenter = new CLLocationCoordinate2D (userLat, userLon); // var mapRegion = MKCoordinateRegion.FromDistance (mapCenter, 2000, 2000); // map.CenterCoordinate = mapCenter; // map.Region = mapRegion; //let's do some annotations - don't forget the class-level declarations // // add an annotation // map.AddAnnotation (new MKPointAnnotation () { // Title = "MyAnnotation", // Coordinate = new CLLocationCoordinate2D (42.364260, -71.120824) // }); // // // set the map delegate // mapDel = new MyMapDelegate (); // map.Delegate = mapDel; // // // add a custom annotation // map.AddAnnotation (new MonkeyAnnotation ("Xamarin", mapCenter)); // add an overlay // var circleOverlay = MKCircle.Circle (mapCenter, 1000); // map.AddOverlay (circleOverlay); }