From c4dcf7f00aeb1cdbd770a7391e068130f0e25473 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Tue, 31 Jan 2017 15:47:42 +0100 Subject: [PATCH] geolocation --- ZicMoove/ZicMoove.Droid/MainActivity.cs | 21 ++--------- ZicMoove/ZicMoove/App.xaml.cs | 12 +++++++ .../ZicMoove/Model/Auth/GCRegIdDeclaration.cs | 27 ++++++++++++++ ZicMoove/ZicMoove/Model/Social/Location.cs | 11 +++++- .../{Oooops => EstimatePages}/PinPage.cs | 35 +++++++++++-------- .../Pages/UserProfile/AccountChooserPage.xaml | 2 +- .../UserProfile/UserProfileViewModel.cs | 4 --- ZicMoove/ZicMoove/ZicMoove.csproj | 9 ++++- 8 files changed, 81 insertions(+), 40 deletions(-) create mode 100644 ZicMoove/ZicMoove/Model/Auth/GCRegIdDeclaration.cs rename ZicMoove/ZicMoove/Pages/{Oooops => EstimatePages}/PinPage.cs (76%) diff --git a/ZicMoove/ZicMoove.Droid/MainActivity.cs b/ZicMoove/ZicMoove.Droid/MainActivity.cs index e9da08ee..702248eb 100644 --- a/ZicMoove/ZicMoove.Droid/MainActivity.cs +++ b/ZicMoove/ZicMoove.Droid/MainActivity.cs @@ -48,6 +48,7 @@ namespace ZicMoove.Droid using Model.Auth.Account; using static Android.Manifest; using Settings; + using Model.Auth; [Activity(Name = "fr.pschneider.bas.MainActivity", Label = "ZicMoove", Theme = "@style/MainTheme", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : @@ -398,28 +399,12 @@ namespace ZicMoove.Droid // TODO handle } - public class GCMDeclaration : IGCMDeclaration - { - public string DeviceId - { get; set; } - - public string GCMRegistrationId - { get; set; } - - public string Model - { get; set; } - - public string Platform - { get; set; } - - public string Version - { get; set; } - } + public IGCMDeclaration GetDeviceInfo() { var devinfo = CrossDeviceInfo.Current; - return new GCMDeclaration + return new GCMRegIdDeclaration { DeviceId = devinfo.Id, GCMRegistrationId = MainSettings.GoogleRegId, diff --git a/ZicMoove/ZicMoove/App.xaml.cs b/ZicMoove/ZicMoove/App.xaml.cs index 36a29144..3a83e21c 100644 --- a/ZicMoove/ZicMoove/App.xaml.cs +++ b/ZicMoove/ZicMoove/App.xaml.cs @@ -197,6 +197,7 @@ namespace ZicMoove { get { return userProfilePage; } } ChatPage chatPage; + PinPage pinPage; public static void ShowPage(Page page) { @@ -248,6 +249,9 @@ namespace ZicMoove Icon = "", BindingContext = new ChatViewModel() }; + + pinPage = new PinPage(); + // var mainPage = new NavigationPage(bQueriesPage); masterDetail = new ExtendedMasterDetailPage() @@ -293,6 +297,14 @@ namespace ZicMoove () => { ShowPage(chatPage); } ) }; + ToolbarItem tiPinPage = new ToolbarItem() + { + Text = "Map", + Icon = "glyphish_103_map.png", + Command = new Command( + () => { ShowPage(pinPage); } + ) + }; masterDetail.ToolbarItems.Add(tiHome); masterDetail.ToolbarItems.Add(tiSetts); masterDetail.ToolbarItems.Add(tiPubChat); diff --git a/ZicMoove/ZicMoove/Model/Auth/GCRegIdDeclaration.cs b/ZicMoove/ZicMoove/Model/Auth/GCRegIdDeclaration.cs new file mode 100644 index 00000000..46743dc2 --- /dev/null +++ b/ZicMoove/ZicMoove/Model/Auth/GCRegIdDeclaration.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yavsc.Models.Identity; + +namespace ZicMoove.Model.Auth +{ + public class GCMRegIdDeclaration : IGCMDeclaration + { + public string DeviceId + { get; set; } + + public string GCMRegistrationId + { get; set; } + + public string Model + { get; set; } + + public string Platform + { get; set; } + + public string Version + { get; set; } + } +} diff --git a/ZicMoove/ZicMoove/Model/Social/Location.cs b/ZicMoove/ZicMoove/Model/Social/Location.cs index d922015a..69509a58 100644 --- a/ZicMoove/ZicMoove/Model/Social/Location.cs +++ b/ZicMoove/ZicMoove/Model/Social/Location.cs @@ -12,10 +12,19 @@ namespace ZicMoove.Model.Social /// public class Position { + public Position() + { + } + + public Position(double lat, double lon) + { + Latitude = lat; + Longitude = lon; + } + /// /// The longitude. /// - public double Longitude { get; set; } /// diff --git a/ZicMoove/ZicMoove/Pages/Oooops/PinPage.cs b/ZicMoove/ZicMoove/Pages/EstimatePages/PinPage.cs similarity index 76% rename from ZicMoove/ZicMoove/Pages/Oooops/PinPage.cs rename to ZicMoove/ZicMoove/Pages/EstimatePages/PinPage.cs index 686d958a..afd6338b 100644 --- a/ZicMoove/ZicMoove/Pages/Oooops/PinPage.cs +++ b/ZicMoove/ZicMoove/Pages/EstimatePages/PinPage.cs @@ -3,23 +3,27 @@ using System; using Xamarin.Forms; using Xamarin.Forms.Maps; using Yavsc; +using ZicMoove.Data; +using System.Threading.Tasks; +using XLabs.Platform.Services.Geolocation; +using Plugin.Geolocator; namespace ZicMoove.Pages { public class PinPage : ContentPage { Map map; - /* - protected async Task GetPos() { + + protected async Task GetPos() { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; - return await locator.GetPositionAsync (timeout: 10000); + return await locator.GetPositionAsync (10000); } - private Position _pos; - public Position MyPosition { + private Model.Social.Position _pos; + public Model.Social.Position MyPosition { get { return _pos; } @@ -28,9 +32,9 @@ namespace ZicMoove.Pages public async Task UpdateMyPos() { var pos = await GetPos(); - _pos = new Position(pos.Latitude,pos.Longitude); + _pos = new Model.Social.Position(pos.Latitude,pos.Longitude); } -*/ + protected override void OnAppearing () { base.OnAppearing (); @@ -49,19 +53,20 @@ namespace ZicMoove.Pages double lat=0; double lon=0; int pc = 0; - foreach (LocalizedEvent ev in Manager.Events) { - var pin = new Pin { + foreach (var query in DataManager.Instance.BookQueries) + { + var pin = new Pin { Type = PinType.SearchResult, Position = new Xamarin.Forms.Maps.Position( - ev.Location.Latitude, ev.Location.Longitude), - Label = ev.Title, - Address = ev.Location.Address + query.Location.Latitude, query.Location.Longitude), + Label = query.Reason, + Address = query.Location.Address }; - pin.BindingContext = ev; + pin.BindingContext = query; map.Pins.Add (pin); // TODO find a true solution - lat = (lat * pc + ev.Location.Latitude) / (pc + 1); - lon = (lon * pc + ev.Location.Longitude) / (pc + 1); + lat = (lat * pc + query.Location.Latitude) / (pc + 1); + lon = (lon * pc + query.Location.Longitude) / (pc + 1); pc++; } // TODO build a MapSpan covering events diff --git a/ZicMoove/ZicMoove/Pages/UserProfile/AccountChooserPage.xaml b/ZicMoove/ZicMoove/Pages/UserProfile/AccountChooserPage.xaml index 710f4fd9..7293e838 100644 --- a/ZicMoove/ZicMoove/Pages/UserProfile/AccountChooserPage.xaml +++ b/ZicMoove/ZicMoove/Pages/UserProfile/AccountChooserPage.xaml @@ -14,7 +14,7 @@ diff --git a/ZicMoove/ZicMoove/ViewModels/UserProfile/UserProfileViewModel.cs b/ZicMoove/ZicMoove/ViewModels/UserProfile/UserProfileViewModel.cs index 7cb81eeb..cfb4cefe 100644 --- a/ZicMoove/ZicMoove/ViewModels/UserProfile/UserProfileViewModel.cs +++ b/ZicMoove/ZicMoove/ViewModels/UserProfile/UserProfileViewModel.cs @@ -4,8 +4,6 @@ using Xamarin.Forms; using XLabs.Forms.Behaviors; using XLabs.Forms.Controls; using XLabs.Forms.Mvvm; -using XLabs.Ioc; -using XLabs.Platform.Services; namespace ZicMoove.ViewModels.UserProfile { @@ -138,8 +136,6 @@ namespace ZicMoove.ViewModels.UserProfile } } - private bool userIsPro = false; - public UserProfileViewModel() { Accounts = MainSettings.AccountList; diff --git a/ZicMoove/ZicMoove/ZicMoove.csproj b/ZicMoove/ZicMoove/ZicMoove.csproj index e19d161d..c97f3230 100644 --- a/ZicMoove/ZicMoove/ZicMoove.csproj +++ b/ZicMoove/ZicMoove/ZicMoove.csproj @@ -68,6 +68,7 @@ + @@ -219,7 +220,7 @@ HomePage.xaml - + @@ -299,6 +300,12 @@ ..\..\packages\Xam.Plugin.Connectivity.2.2.12\lib\MonoAndroid10\Plugin.Connectivity.Abstractions.dll + + ..\..\packages\Xam.Plugin.Geolocator.3.0.4\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.Geolocator.dll + + + ..\..\packages\Xam.Plugin.Geolocator.3.0.4\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.Geolocator.Abstractions.dll + ..\..\packages\Xam.Plugin.Media.2.3.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Plugin.Media.dll