예제 #1
0
        /// <summary>
        /// Search for nearby places
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <param name="types">Pipe-delimited list of place types</param>
        /// <param name="callback"></param>
        public async void Search(double latitude, double longitude, string types, Action<PlacesList> callback)
        {
            var client = new WebClient();
            InitSearch();

			//string url = string.Format(PlacesSearchUrl, latitude, longitude, ApiKey, types);
			string url = string.Format(PlacesSearchUrl, latitude, longitude, _apiKey, types);
            Log.Info("PlacesUrl", url);

            var placeList = await client.DownloadStringTaskAsync(new Uri(url));
            //_placesList = placeList.FromJson<PlacesList>();
            _placesList = JsonConvert.DeserializeObject<PlacesList>(placeList);
            SearchCompleted(callback);

            GetReportedCrueltySpotsAsync(callback);
        }
예제 #2
0
        /// <summary>
        /// Search for nearby place with specific name
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <param name="types"></param>
        /// <param name="name"></param>
        /// <param name="callback"></param>
        public async void Search(double latitude, double longitude, string types, string name, Action<PlacesList> callback)
        {
            if (!string.IsNullOrWhiteSpace(name))
            {
                var client = new WebClient();
                InitSearch();
				//string url = string.Format(PlacesSearchByNameUrl, latitude, longitude, ApiKey, types, name);
				string url = string.Format(PlacesSearchByNameUrl, latitude, longitude, _apiKey, types, name);

                Log.Info("PlacesByNameUrl", url);

                var placeList = await client.DownloadStringTaskAsync(new Uri(url));
                //_placesList = placeList.FromJson<PlacesList>();
                _placesList = JsonConvert.DeserializeObject<PlacesList>(placeList);
                SearchCompleted(callback);

                GetReportedCrueltySpotsAsync(callback);
            }
            else
            {
                // Name not specified, do search without specifying a name
                Search(latitude, longitude, types, callback);
            }
        }
예제 #3
0
        ///// <summary>
        ///// Get Reported Cruelty Spots with Google Place Ids
        ///// ToDo: This method should accept a lat/lng so we don't retrieve more than we need
        ///// </summary>
        ///// <param name="callback"></param>
        //private void GetReportedCrueltySpotsAsync(Action<PlacesList> callback)
        //{
        //    var crueltySpotsService = new CrueltySpotsService();
        //    crueltySpotsService.GetAllGooglePlacesAsync(r =>
        //                                                   {
        //                                                       _reportedGooglePlaces = new Dictionary<string, int>();
        //                                                       foreach (
        //                                                           var crueltySpot in
        //                                                               r.CrueltySpots)
        //                                                       {
        //                                                           if (
        //                                                               !_reportedGooglePlaces.ContainsKey(
        //                                                                   crueltySpot.GooglePlaceId))
        //                                                           {
        //                                                               _reportedGooglePlaces.Add(
        //                                                                   crueltySpot.GooglePlaceId,
        //                                                                   crueltySpot.Id);
        //                                                           }
        //                                                       }
        //                                                       _reportedGooglePlacesRetrieved = true;
        //                                                       SearchCompleted(callback);
        //                                                   });
        //}

        /// <summary>
        /// Start with a clean slate
        /// </summary>
        private void InitSearch()
        {
            _placesList = null;
            _reportedGooglePlacesRetrieved = false;
            _reportedGooglePlaces = null;
        }