Пример #1
0
        private async void ShowRouteToPlace(Place place)
        {
            ProgressDialog pleaseWaitDialog = new ProgressDialog(this);

            pleaseWaitDialog.SetMessage(GetString(Resource.String.please_wait));
            pleaseWaitDialog.SetCancelable(false);
            pleaseWaitDialog.Show();

            try
            {
                MapFragment mapFragment = FragmentManager.FindFragmentByTag <MapFragment>("MAP_FRAGMENT");

                nearestPlace = place;
                Route route = await DirectionsService.GetShortestRoute(
                    mapFragment.MyLocation, place.geometry.location);

                mapFragment.DrawRouteToPlace(route, nearestPlace);
            }
            catch (ApiCallException)
            {
            }
            catch (DirectionsException)
            {
            }
            finally
            {
                pleaseWaitDialog.Cancel();
            }
        }
Пример #2
0
        private async void ShowRouteToNearestAddress(string query)
        {
            CheckInternetConnection();

            if (!string.IsNullOrWhiteSpace(query))
            {
                ProgressDialog pleaseWaitDialog = new ProgressDialog(this);
                pleaseWaitDialog.SetMessage(GetString(Resource.String.please_wait));
                pleaseWaitDialog.SetCancelable(false);
                pleaseWaitDialog.Show();

                try
                {
                    MapFragment mapFragment = FragmentManager.FindFragmentByTag <MapFragment>("MAP_FRAGMENT");

                    if (mapFragment.MyLocation == null)
                    {
                        AWidget.Toast.MakeText(this, GetString(Resource.String.my_location_unavaliable),
                                               AWidget.ToastLength.Short).Show();
                        return;
                    }

                    List <Place> places = await PlacesService.GetPlacesByQuery(query, mapFragment.MyLocation);

                    if (places.Count == 0)
                    {
                        AWidget.Toast.MakeText(this, GetString(Resource.String.no_places_found),
                                               AWidget.ToastLength.Short).Show();
                        return;
                    }

                    nearestPlace = null;
                    Route shortestRoute = null;
                    foreach (var place in places)
                    {
                        var route = await DirectionsService.GetShortestRoute(
                            mapFragment.MyLocation, place.geometry.location);

                        if (shortestRoute == null)
                        {
                            nearestPlace  = place;
                            shortestRoute = route;
                        }
                        else if (route.legs[0].distance.value < shortestRoute.legs[0].distance.value)
                        {
                            nearestPlace  = place;
                            shortestRoute = route;
                        }
                    }

                    mapFragment.DrawRouteToPlace(shortestRoute, nearestPlace);
                    OnPrepareOptionsMenu(actionBarMenu);
                    actionBarMenu.FindItem(Resource.Id.action_add_to_fav).SetVisible(true);
                }
                catch (ApiCallException)
                {
                }
                catch (NearbyPlacesSearchException)
                {
                }
                catch (DirectionsException)
                {
                }
                finally
                {
                    pleaseWaitDialog.Cancel();
                }
            }
        }