Ejemplo n.º 1
0
        public async Task GetDetails(string id)
        {
            if (this._apiClient == null || !this._apiClient.IsConnected)
            {
                ConnectToPlacesAPI();
            }

            PlaceBuffer nativeResult = await PlacesClass.GeoDataApi.GetPlaceByIdAsync(this._apiClient, id);

            if (nativeResult == null || !nativeResult.Any())
            {
                return;
            }

            IPlace nativeDetails = nativeResult.First();

            this.AddMarker(nativeDetails.NameFormatted.ToString(), nativeDetails.LatLng);

            //return new TKPlaceDetails
            //{
            //    Coordinate = nativeDetails.LatLng.ToPosition(),
            //    FormattedAddress = nativeDetails.AddressFormatted.ToString(),
            //    InternationalPhoneNumber = nativeDetails.PhoneNumberFormatted?.ToString(),
            //    Website = nativeDetails.WebsiteUri?.ToString()
            //};
        }
Ejemplo n.º 2
0
        public async Task GetPredictionsFromPlacesAPI(string searchText, LatLngBounds bounds)
        {
            if (this._apiClient == null || !this._apiClient.IsConnected)
            {
                ConnectToPlacesAPI();
            }

            //List<IPlaceResult> result = new List<IPlaceResult>();

            if (autocompletePredictionBuffer != null)
            {
                autocompletePredictionBuffer.Dispose();
                autocompletePredictionBuffer = null;
            }

            autocompletePredictionBuffer = await PlacesClass.GeoDataApi.GetAutocompletePredictionsAsync(this._apiClient, searchText, bounds, null);

            if (autocompletePredictionBuffer != null)
            {
                if (autocompletePredictionBuffer.Status.IsSuccess)
                {
                    if (autocompletePredictionBuffer.Count > 0)
                    {
                        ClearRoute(null, null);

                        IAutocompletePrediction pred;
                        List <string>           placeIds = new List <string>();

                        for (int i = 0; i < autocompletePredictionBuffer.Count; i++)
                        {
                            pred = autocompletePredictionBuffer.ElementAt(i);
                            placeIds.Add(pred.PlaceId);
                        }

                        PlaceBuffer placeBuffer = await PlacesClass.GeoDataApi.GetPlaceByIdAsync(this._apiClient, placeIds.ToArray());

                        if (placeBuffer == null || !placeBuffer.Any())
                        {
                            System.Diagnostics.Debug.WriteLine("No results found for individual place details for search: " + searchText);
                            return;
                        }
                        else
                        {
                            IPlace placeDetails;
                            LatLngBounds.Builder builder = new LatLngBounds.Builder();

                            for (int i = 0; i < placeBuffer.Count; i++)
                            {
                                placeDetails = placeBuffer.ElementAt(i);

                                this.AddMarker(placeDetails.NameFormatted.ToString(), placeDetails.LatLng);

                                builder.Include(placeDetails.LatLng);
                            }

                            LatLngBounds newBounds = builder.Build();
                            CameraUpdate cu        = CameraUpdateFactory.NewLatLngBounds(newBounds, 120);
                            googleMap.AnimateCamera(cu);
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("No results found for search: " + searchText);
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine(autocompletePredictionBuffer.Status.StatusMessage);
                }

                //result.AddRange(this._buffer.Select(i =>
                //    new TKNativeAndroidPlaceResult
                //    {
                //        Description = i.GetPrimaryText(null),
                //        Subtitle = i.GetSecondaryText(null),
                //        PlaceId = i.PlaceId,
                //    }));
            }

            //return result;
        }