Esempio n. 1
0
        ///<inheritdoc/>
        public async Task <IEnumerable <IPlaceResult> > GetPredictions(string query, MapSpan bounds)
        {
            if (this._apiClient == null || !this._apiClient.IsConnected)
            {
                this.Connect();
            }

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

            LatLngBounds latLngBounds = null;

            if (bounds != null)
            {
                double mDistanceInMeters = bounds.Radius.Meters;

                double latRadian = bounds.LatitudeDegrees;

                double degLatKm  = 110.574235;
                double degLongKm = 110.572833 * Math.Cos(latRadian);
                double deltaLat  = mDistanceInMeters / 1000.0 / degLatKm;
                double deltaLong = mDistanceInMeters / 1000.0 / degLongKm;

                double minLat  = bounds.Center.Latitude - deltaLat;
                double minLong = bounds.Center.Longitude - deltaLong;
                double maxLat  = bounds.Center.Latitude + deltaLat;
                double maxLong = bounds.Center.Longitude + deltaLong;

                latLngBounds = new LatLngBounds(new LatLng(minLat, minLong), new LatLng(maxLat, maxLong));
            }

            if (this._buffer != null)
            {
                this._buffer.Dispose();
                this._buffer = null;
            }

            this._buffer = await PlacesClass.GeoDataApi.GetAutocompletePredictionsAsync(
                this._apiClient,
                query,
                latLngBounds,
                null);

            if (this._buffer != null)
            {
                result.AddRange(this._buffer.Select(i =>
                                                    new NativeAndroidPlaceResult
                {
                    Description = i.GetPrimaryText(null),
                    Subtitle    = i.GetSecondaryText(null),
                    PlaceId     = i.PlaceId,
                }));
            }
            return(result);
        }
        ///<inheritdoc/>
        public async Task<IEnumerable<IPlaceResult>> GetPredictions(string query, MapSpan bounds)
        {
            if (this._apiClient == null || !this._apiClient.IsConnected) this.Connect();

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

            double mDistanceInMeters = bounds.Radius.Meters;
            
            double latRadian = bounds.LatitudeDegrees;

            double degLatKm = 110.574235;
            double degLongKm = 110.572833 * Math.Cos(latRadian);
            double deltaLat = mDistanceInMeters / 1000.0 / degLatKm;
            double deltaLong = mDistanceInMeters / 1000.0 / degLongKm;

            double minLat = bounds.Center.Latitude - deltaLat;
            double minLong = bounds.Center.Longitude - deltaLong;
            double maxLat = bounds.Center.Latitude + deltaLat;
            double maxLong = bounds.Center.Longitude + deltaLong;

            if (this._buffer != null)
            {
                this._buffer.Dispose();
                this._buffer = null;
            }

            this._buffer = await PlacesClass.GeoDataApi.GetAutocompletePredictionsAsync(
                this._apiClient, 
                query, 
                new LatLngBounds(new LatLng(minLat, minLong), new LatLng(maxLat, maxLong)), 
                null);
            
            if (this._buffer != null)
            {
                result.AddRange(this._buffer.Select(i => 
                    new TKNativeAndroidPlaceResult
                    {
                        Description = i.Description,
                        PlaceId = i.PlaceId,
                    }));
            }
            return result;
        }
Esempio n. 3
0
        ///<inheritdoc/>
        public void DisconnectAndRelease()
        {
            if (apiClient == null)
            {
                return;
            }

            if (apiClient.IsConnected)
            {
                apiClient.Disconnect();
            }

            apiClient.Dispose();
            apiClient = null;

            if (buffer != null)
            {
                buffer.Dispose();
                buffer = null;
            }
        }
Esempio n. 4
0
        ///<inheritdoc/>
        public void DisconnectAndRelease()
        {
            if (this._apiClient == null)
            {
                return;
            }

            if (this._apiClient.IsConnected)
            {
                this._apiClient.Disconnect();
            }

            this._apiClient.Dispose();
            this._apiClient = null;

            if (this._buffer != null)
            {
                this._buffer.Dispose();
                this._buffer = null;
            }
        }
        ///<inheritdoc/>
        public void DisconnectAndRelease()
        {
            if (_apiClient == null)
            {
                return;
            }

            if (_apiClient.IsConnected)
            {
                _apiClient.Disconnect();
            }

            _apiClient.Dispose();
            _apiClient = null;

            if (_buffer != null)
            {
                _buffer.Dispose();
                _buffer = null;
            }
        }
Esempio n. 6
0
        public void DisconnectAndReleasePlacesAPI()
        {
            if (this._apiClient == null)
            {
                return;
            }

            if (this._apiClient.IsConnected)
            {
                this._apiClient.Disconnect();
            }

            this._apiClient.Dispose();
            this._apiClient = null;

            if (this.autocompletePredictionBuffer != null)
            {
                this.autocompletePredictionBuffer.Dispose();
                this.autocompletePredictionBuffer = null;
            }
        }
Esempio n. 7
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;
        }