Example #1
0
                void UpdateMap(bool result)
                {
                    if (GroupEntries.Count > 0)
                    {
                        // update our list and display
                        SearchResultPrefix.Text = ConnectStrings.GroupFinder_Neighborhood;

                        (ListView.Adapter as GroupArrayAdapter).SetSelectedRow(0);

                        // for the map, ensure it's valid, because Google Play can fail
                        if (Map != null)
                        {
                            Map.Clear( );
                            MarkerList.Clear( );

                            Android.Gms.Maps.Model.LatLngBounds.Builder builder = new Android.Gms.Maps.Model.LatLngBounds.Builder();

                            // add the source position
                            Android.Gms.Maps.Model.MarkerOptions markerOptions = new Android.Gms.Maps.Model.MarkerOptions();
                            Android.Gms.Maps.Model.LatLng        pos           = new Android.Gms.Maps.Model.LatLng(SourceLocation.Latitude, SourceLocation.Longitude);
                            markerOptions.SetPosition(pos);
                            markerOptions.InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
                            builder.Include(pos);

                            Android.Gms.Maps.Model.Marker marker = Map.AddMarker(markerOptions);
                            MarkerList.Add(marker);

                            for (int i = 0; i < GroupEntries.Count; i++)
                            {
                                // add the positions to the map
                                markerOptions = new Android.Gms.Maps.Model.MarkerOptions();
                                pos           = new Android.Gms.Maps.Model.LatLng(GroupEntries[i].Latitude, GroupEntries[i].Longitude);
                                markerOptions.SetPosition(pos);
                                markerOptions.SetTitle(GroupEntries[i].Name);
                                markerOptions.SetSnippet(string.Format("{0:##.0} {1}", GroupEntries[i].DistanceFromSource, ConnectStrings.GroupFinder_MilesSuffix));

                                builder.Include(pos);

                                marker = Map.AddMarker(markerOptions);
                                MarkerList.Add(marker);
                            }

                            Android.Gms.Maps.Model.LatLngBounds bounds = builder.Build( );

                            int paddingInPixels = Math.Min(View.Width, (int)(View.Height * .1f));

                            CameraUpdate camPos = CameraUpdateFactory.NewLatLngBounds(bounds, paddingInPixels);
                            Map.AnimateCamera(camPos);

                            // show the info window for the first (closest) group
                            MarkerList[1].ShowInfoWindow( );
                        }
                    }
                    else
                    {
                        if (result == true)
                        {
                            // send the analytic and update our list
                            SearchResultPrefix.Text       = ConnectStrings.GroupFinder_NoGroupsFound;
                            SearchResultNeighborhood.Text = string.Empty;

                            (ListView.Adapter as GroupArrayAdapter).SetSelectedRow(-1);

                            // validate the map before using. Google Play can error
                            if (Map != null)
                            {
                                // no groups found, so move the camera to the default position
                                Android.Gms.Maps.Model.LatLng defaultPos = new Android.Gms.Maps.Model.LatLng(ConnectConfig.GroupFinder_DefaultLatitude, ConnectConfig.GroupFinder_DefaultLongitude);
                                CameraUpdate camPos = CameraUpdateFactory.NewLatLngZoom(defaultPos, ConnectConfig.GroupFinder_DefaultScale_Android);
                                Map.AnimateCamera(camPos);
                            }
                        }
                        else
                        {
                            // there was actually an error. Let them know.
                            SearchResultPrefix.Text       = ConnectStrings.GroupFinder_NetworkError;
                            SearchResultNeighborhood.Text = string.Empty;
                        }
                    }
                }