private async void LoadUserTraps() { try { List <ArmedTrapApiResult> response = await TrapApiService.ListArmed(); if (response != null && response.Count > 0) { List <BasicGeoposition> basicPositions = new List <BasicGeoposition>(); foreach (var trapPlanted in response) { RandomAccessStreamReference mapIconStreamReference = null; if (trapPlanted.NameKey == ETrap.BEAR.ToString()) { mapIconStreamReference = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/trap_bear_trap_selected_icon.png")); } else if (trapPlanted.NameKey == ETrap.MINE.ToString()) { mapIconStreamReference = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/trap_mine_trap_selected_icon.png")); } else if (trapPlanted.NameKey == ETrap.PIT.ToString()) { mapIconStreamReference = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/trap_pit_trap_selected_icon.png")); } else if (trapPlanted.NameKey == ETrap.DOGS.ToString()) { mapIconStreamReference = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/trap_dogs_trap_selected_icon.png")); } else { continue; } MapIcon mapIcon = new MapIcon(); mapIcon.Location = new Geopoint(new BasicGeoposition() { Latitude = trapPlanted.Latitude, Longitude = trapPlanted.Longitude }); mapIcon.NormalizedAnchorPoint = new Point(0.5, 1.0); mapIcon.Title = trapPlanted.Date.ToLocalTime().ToString(); mapIcon.Image = mapIconStreamReference; mapIcon.ZIndex = 0; map.MapElements.Add(mapIcon); basicPositions.Add(new BasicGeoposition() { Latitude = trapPlanted.Latitude, Longitude = trapPlanted.Longitude }); } if (response.Count > 1) { await map.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(basicPositions), null, MapAnimationKind.Default); } else { map.Center = new Geopoint(new BasicGeoposition() { Latitude = response[0].Latitude, Longitude = response[0].Longitude }); } } else { var dialog = new MessageDialog("You didn't put traps :("); dialog.Title = "Warning"; dialog.Commands.Add(new UICommand { Label = "Ok", Id = 0 }); var res = await dialog.ShowAsync(); if ((int)res.Id == 0) { AppShell.Current.AppFrame.Navigate(typeof(HomePage)); } } } catch (Exception exception) { } }
private async void LoadUserTraps() { try { List <ArmedTrapApiResult> response = await TrapApiService.ListArmed(); if (response != null && response.Count > 0) { var boundsBuilders = new LatLngBounds.Builder(); foreach (var trapPlanted in response) { var idIcon = 0; if (trapPlanted.NameKey == ETrap.BEAR.ToString()) { idIcon = MyTrap.Droid.Resource.Drawable.trap_bear_trap_selected_icon; } else if (trapPlanted.NameKey == ETrap.MINE.ToString()) { idIcon = MyTrap.Droid.Resource.Drawable.trap_mine_trap_selected_icon; } else if (trapPlanted.NameKey == ETrap.PIT.ToString()) { idIcon = MyTrap.Droid.Resource.Drawable.trap_pit_trap_selected_icon; } else if (trapPlanted.NameKey == ETrap.DOGS.ToString()) { idIcon = MyTrap.Droid.Resource.Drawable.trap_dogs_trap_selected_icon; } //else if (trapPlanted.NameKey == ETrap.LOOP.ToString()) else { //idIcon = MyTrap.Droid.Resource.Drawable.trap_loop_trap_icon; continue; } var position = new LatLng(trapPlanted.Latitude, trapPlanted.Longitude); googleMap.AddMarker(new MarkerOptions() .SetPosition(position) .SetTitle(trapPlanted.Date.ToLocalTime().ToString(Resources.GetString(MyTrap.Droid.Resource.String.format_date_hour_minute))) .SetIcon(BitmapDescriptorFactory.FromResource(idIcon)) ); int fillColor = Int32.Parse("80f15f4b", System.Globalization.NumberStyles.HexNumber); CircleOptions circleOptions = new CircleOptions(); circleOptions.InvokeCenter(position); circleOptions.InvokeFillColor(fillColor); circleOptions.InvokeStrokeWidth(3); googleMap.AddCircle(circleOptions); boundsBuilders.Include(new LatLng(trapPlanted.Latitude, trapPlanted.Longitude)); } if (response.Count > 1) { var bounds = boundsBuilders.Build(); googleMap.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 100)); } else { googleMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(response[0].Latitude, response[0].Longitude), 16)); } } else { HomeActivity homeActivity = (HomeActivity)Activity; new AlertDialog.Builder(Activity) .SetIcon(Android.Resource.Drawable.IcDialogAlert) .SetTitle(MyTrap.Droid.Resource.String.alert_title_error) .SetMessage(MyTrap.Droid.Resource.String.no_traps_armed) .SetPositiveButton(MyTrap.Droid.Resource.String.ok, new MyDialogClickListener(homeActivity)) .SetCancelable(false) .Show(); } progressDialog.Cancel(); } catch (Exception exception) { InsightsUtils.LogException(exception); } }