示例#1
0
        async void Start()
        {
            UniMapInitializer.Initialize();

            var request = new NearbySearchRequest("KEY")
            {
                radius = 1000,
                type   = PlaceType.Atm
            };

            // Callback search
            request.Send(
                new Location(48.8, 2.35),
                result => Debug.Log(JsonUtility.ToJson(result)),
                exception => Debug.LogError(exception)
                );

            // Task search
            try {
                var response = await request.Send(new Location(40.0, 2.35));

                Debug.Log(JsonUtility.ToJson(response));
            }
            catch (Exception e) {
                Debug.LogError(e);
            }
        }
示例#2
0
        public object Search(string latitude, string longitude, string type)
        {
            string apiKey = WebConfigurationManager.AppSettings["GoogleApiKey"];

            NearbySearchRequest request = new NearbySearchRequest(apiKey, latitude, longitude, "1000", type);

            try
            {
                NearbySearchResponse result = request.Execute();

                return(JsonConvert.SerializeObject(result.Results.Select(
                                                       x => new object[]
                {
                    x.Icon,
                    x.Name,
                    x.Opening_hours != null ? x.Opening_hours.Open_now ? "YES" : "NO" : "",
                    x.Types.Select(y => y.Replace("_", " ")).Aggregate((a, b) => a + ", " + b),
                    x.Vicinity
                })
                                                   ));
            }
            catch (ApplicationException ex)
            {
                return(string.Empty);
            }
        }
        public async Task <IList <Restaurant> > GetRestaurantsAsync(Position position)
        {
            tcsResult = new TaskCompletionSource <bool>();

            _searchService = SearchServiceFactory.Create(Android.App.Application.Context, Android.Net.Uri.Encode("YOUR_API_KEY"));

            // Create SearchRequest
            NearbySearchRequest nearbySearchRequest = new NearbySearchRequest();

            nearbySearchRequest.Query         = "Istanbul";
            nearbySearchRequest.Language      = "en";
            nearbySearchRequest.PoliticalView = "TR";
            // Set Poi type as Restaurant
            nearbySearchRequest.PoiType = LocationType.Restaurant;
            //Set user's location for nearest restaurant search
            nearbySearchRequest.Location  = new Coordinate(position.Latitude, position.Longitude);
            nearbySearchRequest.Radius    = Java.Lang.Integer.ValueOf(10000);
            nearbySearchRequest.PageIndex = Java.Lang.Integer.ValueOf(1);
            nearbySearchRequest.PageSize  = Java.Lang.Integer.ValueOf(10);

            // Call the nearby place search API.
            _searchService.NearbySearch(nearbySearchRequest, this);

            await tcsResult.Task;

            return(restaurants);
        }
        public void OnClick(View view)
        {
            string     queryText   = queryInput.Text;
            string     language    = languageInput.Text;
            string     countryCode = countryCodeInput.Text;
            double     lat         = double.Parse(latitudeInput.Text, CultureInfo.InvariantCulture);
            double     lon         = double.Parse(longitudeInput.Text, CultureInfo.InvariantCulture);
            Coordinate location    = new Coordinate(lat, lon);

            Java.Lang.Integer radius    = Java.Lang.Integer.ValueOf(radiusInput.Text);
            Java.Lang.Integer pageIndex = Java.Lang.Integer.ValueOf(pageIndexInput.Text);
            Java.Lang.Integer pageSize  = Java.Lang.Integer.ValueOf(pageSizeInput.Text);

            switch (view.Id)
            {
            case Resource.Id.btn_search_place:
                TextSearchRequest textSearchRequest = new TextSearchRequest();
                textSearchRequest.Query       = queryText;
                textSearchRequest.Language    = language;
                textSearchRequest.CountryCode = countryCode;
                textSearchRequest.Location    = location;
                textSearchRequest.Radius      = radius;
                textSearchRequest.PageIndex   = pageIndex;
                textSearchRequest.PageSize    = pageSize;

                TextSearchResultListener textSearchResultListener = new TextSearchResultListener();
                searchService.TextSearch(textSearchRequest, textSearchResultListener);

                break;

            case Resource.Id.btn_search_nearby_place:
                NearbySearchRequest nearbySearchRequest = new NearbySearchRequest();
                nearbySearchRequest.Query     = queryText;
                nearbySearchRequest.Language  = language;
                nearbySearchRequest.Location  = location;
                nearbySearchRequest.Radius    = radius;
                nearbySearchRequest.PageIndex = pageIndex;
                nearbySearchRequest.PageSize  = pageSize;

                NearbySearchResultListener nearbySearchResultListener = new NearbySearchResultListener();
                searchService.NearbySearch(nearbySearchRequest, nearbySearchResultListener);

                break;

            default:
                break;
            }
        }
        public string GetNearbyPlaceName(VehiclePoint point)
        {
            var           result        = "";
            GoogleSigned  VehicleApiKey = new GoogleSigned("AIzaSyC_iHzls7OqrC2d0OVUERemIyKS8h9BTUE");
            var           service       = new PlacesService(VehicleApiKey);
            PlacesRequest request       = new NearbySearchRequest()
            {
                Location = new LatLng(point.X, point.Y),
            };
            PlacesResponse response = service.GetResponse(request);

            if (response.Results != null && response.Results.Count() > 0)
            {
                result = response.Results.FirstOrDefault().Name;
            }
            return(result);
        }
        public void NearbySearch(LatLng currentLocation, string searchText)
        {
            ISearchService      searchService       = SearchServiceFactory.Create(activity, Android.Net.Uri.Encode("CgB6e3x9NPSZfsfsG8oVcTDTEpTRfRm5A1rF/cT2+mjcQWCv93U9FICe6Do6XM+9w+7ZtPONmSxgxUpOC8HEUV//"));
            NearbySearchRequest nearbySearchRequest = new NearbySearchRequest();

            nearbySearchRequest.Query    = searchText;
            nearbySearchRequest.Language = "en";
            if (currentLocation != null)
            {
                nearbySearchRequest.Location = new Coordinate(currentLocation.Latitude, currentLocation.Longitude);
            }
            nearbySearchRequest.Radius    = (Integer)2000;
            nearbySearchRequest.PageIndex = (Integer)1;
            nearbySearchRequest.PageSize  = (Integer)5;
            nearbySearchRequest.PoiType   = LocationType.Address;
            searchService.NearbySearch(nearbySearchRequest, new QuerySuggestionResultListener(activity as MainActivity));
        }
示例#7
0
        public Task <FetchResponse <Results <NearbySearch> > > NearbySearch(
            string location,
            long?radius,
            string key,
            string keyword  = null,
            string language = null,
            string name     = null,
            string type     = null)
        {
            var request = new NearbySearchRequest();

            if (!string.IsNullOrEmpty(location))
            {
                request.location = location;
            }

            if (radius.HasValue)
            {
                request.radius = radius.Value;
            }

            if (!string.IsNullOrEmpty(keyword))
            {
                request.keyword = keyword;
            }

            if (!string.IsNullOrEmpty(language))
            {
                request.language = language;
            }

            if (!string.IsNullOrEmpty(name))
            {
                request.name = name;
            }

            if (!string.IsNullOrEmpty(type))
            {
                request.type = type;
            }

            return(client.Places.NearbySearch(request, key));
        }
示例#8
0
        public void PlacesTest_Nearby()
        {
            PlacesRequest request = new NearbySearchRequest()
            {
                Location = new LatLng(40.741895, -73.989308),
                Radius   = 10000,
                Sensor   = false
            };
            PlacesResponse response = new PlacesService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);

            // Google requires a delay before resending page token value
            Thread.Sleep(2000);

            // setting the PageToken value should result in valid request
            request = new NearbySearchRequest()
            {
                Location  = new LatLng(40.741895, -73.989308),
                Radius    = 10000,
                Sensor    = false,
                PageToken = response.NextPageToken
            };
            response = new PlacesService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);

            // Google requires a delay before resending page token value
            Thread.Sleep(1100);

            // setting an invalid page token should result in InvalidRequest status
            request = new NearbySearchRequest()
            {
                Location  = new LatLng(40.741895, -73.989308),
                Radius    = 10000,
                Sensor    = false,
                PageToken = response.NextPageToken + "A"                 // invalid token
            };
            response = new PlacesService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.InvalidRequest, response.Status);
        }
    void Start()
    {
        var request = new NearbySearchRequest("KEY")
        {
            radius = 1000,
            type   = PlaceType.Atm
        };

        // Callback search
        request.Send(
            new Location(48.8, 2.35),
            result => Debug.Log(JsonUtility.ToJson(result)),
            exception => Debug.LogError(exception)
            );

        // Promise search
        request.Send(new Location(48.8, 2.35))
        .Then(response => Debug.Log(JsonUtility.ToJson(response)))
        .Catch(exception => Debug.LogError(exception));
    }
        /// <summary>
        /// Obtains a list of places within a 10 meters radius of the specified latitude and longitude
        /// </summary>
        /// <param name="pLatitude">Latitude</param>
        /// <param name="pLongitude">Longitude</param>
        /// <returns></returns>
        public List <dynamic> PlacesByCoordinates(double pLatitude, double pLongitude)
        {
            PlacesRequest request = new NearbySearchRequest()
            {
                Location = new LatLng(pLatitude, pLongitude),
                Radius   = 10
            };

            PlacesResponse response    = new PlacesService().GetResponse(request);
            List <dynamic> foundPlaces = new List <dynamic>();

            if (response.Status == ServiceResponseStatus.Ok)
            {
                foreach (PlacesResult result in response.Results)
                {
                    dynamic place = new ExpandoObject();
                    place.placeID = result.PlaceId;
                    place.name    = result.Name;
                    place.address = result.FormattedAddress;
                    place.type    = new List <string>();
                    foreach (PlaceType type in result.Types)
                    {
                        place.type.Add(type.ToString());
                    }
                    place.rating = result.Rating;
                    place.photo  = result.Icon;
                    foundPlaces.Add(place);
                }

                return(foundPlaces);
            }
            else
            {
                return(null);
            }
        }
        private void ExecPlaceSearch()
        {
            NearbySearchRequest NearbySearchRequest = new NearbySearchRequest();

            string queryText = QueryInput.Text;

            if (queryText.Length == 0)
            {
                ResultTextView.Text = "Error : Query is empty!";
                return;
            }
            NearbySearchRequest.Query = queryText;

            string language = LanguageInput.Text;

            if (!string.IsNullOrEmpty(LanguageInput.Text))
            {
                NearbySearchRequest.Language = language;
            }

            double lat;
            double lon;

            if (!string.IsNullOrEmpty(LatitudeInput.Text) || !string.IsNullOrEmpty(LongitudeInput.Text))
            {
                if (!(double.TryParse(LatitudeInput.Text, out lat)) || !(double.TryParse(LongitudeInput.Text, out lon)))
                {
                    ResultTextView.Text = "Error : Location is invalid!";
                    return;
                }
                NearbySearchRequest.Location = new Coordinate(lat, lon);
            }

            int radiusInt;

            if (!(Int32.TryParse(RadiusInput.Text, out radiusInt)) || radiusInt <= 0)
            {
                ResultTextView.Text = "Error : Radius Must be greater than 0 !";
                return;
            }
            NearbySearchRequest.Radius = (Integer)radiusInt;


            string pageIndex = PageIndexInput.Text;
            int    pageIndexInt;

            if (!(Int32.TryParse(pageIndex, out pageIndexInt)) || pageIndexInt < 1 || pageIndexInt > 60)
            {
                ResultTextView.Text = "Error : PageIndex Must be between 1 and 60!";
                return;
            }
            NearbySearchRequest.PageIndex = (Integer)pageIndexInt;

            string pageSize = PageSizeInput.Text;
            int    pageSizeInt;

            if (!(Int32.TryParse(pageSize, out pageSizeInt)) || pageSizeInt < 1 || pageSizeInt > 20)
            {
                ResultTextView.Text = "Error : PageSize Must be between 1 and 20!";
                return;
            }
            NearbySearchRequest.PageSize = (Integer)pageSizeInt;

            LocationType poiType = PoiTypeSpinner.Enabled ? (LocationType)PoiTypeSpinner.SelectedItem : null;

            if (poiType != null)
            {
                NearbySearchRequest.PoiType = poiType;
            }

            NearbySearchRequest.StrictBounds = (Java.Lang.Boolean)BoundStrict.Checked;

            NearbySearchResultListener nearbySearchResultListener = new NearbySearchResultListener();

            // Call the search API.
            SearchService.NearbySearch(NearbySearchRequest, nearbySearchResultListener);
        }
示例#12
0
        /// <summary>
        /// The nearby search.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <SearchResponse <NearbySearchResult> > NearbySearch(NearbySearchRequest request)
        {
            var queryParams = PrepareSearchRequestQuery(request);

            return(await _webApi.GetAsync <SearchResponse <NearbySearchResult> >(EndPointUris.PlacesNerbySearch, queryParams));
        }
示例#13
0
        public Task <FetchResponse <Results <NearbySearch> > > NearbySearch(
            NearbySearchRequest request,
            string key)
        {
            var @params = new List <(string, object)>();

            if (!string.IsNullOrEmpty(request.input))
            {
                @params.Add(("input", request.input));
            }

            if (!string.IsNullOrEmpty(request.location))
            {
                @params.Add(("location", request.location));
            }

            if (request.radius.HasValue)
            {
                @params.Add(("radius", request.radius));
            }

            if (!string.IsNullOrEmpty(request.keyword))
            {
                @params.Add(("keyword", request.keyword));
            }

            if (!string.IsNullOrEmpty(request.language))
            {
                @params.Add(("language", request.language));
            }

            if (request.minprice.HasValue)
            {
                @params.Add(("minprice", request.minprice.Value));
            }

            if (request.maxprice.HasValue)
            {
                @params.Add(("maxprice", request.maxprice.Value));
            }

            if (!string.IsNullOrEmpty(request.name))
            {
                @params.Add(("name", request.name));
            }

            // if (!string.IsNullOrEmpty(request.opennow))
            //     @params.Add(("opennow", request.opennow));

            // if (request.rankby.HasValue)
            //     @params.Add(("rankby", Enum.GetName(typeof(Rankby), (int)request.rankby.Value).ToLower()));

            if (!string.IsNullOrEmpty(request.type))
            {
                @params.Add(("type", request.type));
            }

            // if (!string.IsNullOrEmpty(request.pagetoken))
            //     @params.Add(("pagetoken", request.pagetoken));

            return(this.httpClient.ExecuteGet <Results <NearbySearch> >(
                       Utils.GetApiUrl(NEARBY_SEARCH_URL, key, @params)));
        }