//public List<ResultsList> NearestLocationAutocomplete(string latitude, string longitude, string distance, // string address) //{ // if (!string.IsNullOrEmpty(latitude) && !string.IsNullOrEmpty(longitude)) // { // string radiusData = string.Empty; // string url = // "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + // latitude + // "," + // longitude + "&radius=" + distance + "&key=" + // ConfigurationManager.AppSettings["apiKey"]; // url = url + "&name=" + address; // radiusData = webRequest.WebServiceInformation(url); // var returnsInformation = // Newtonsoft.Json.JsonConvert.DeserializeObject<NearBySearchEntity>( // radiusData); // return returnsInformation.results; // } // return null; //} private void InsertSearchResult(NearBySearchEntity returnsInformation, int countryId, string url, string longitude, string latitude, int attractionId, int attractionTravelStepsId, int mapsId, MapsXAPIXFeature mapsXapixFeature) { string radiusData = string.Empty; string urlString = string.Empty; var nearByPlaceSearchEntity = returnsInformation.results.Select(x => new NearByPlaceSearchEntity { AttractionName = x.name, GoogleSearchText = x.vicinity, PlaceId = x.place_id, Latitude = x.geometry.location.lat, Longitude = x.geometry.location.lng, types = string.Join("~", x.types) }).ToList(); dALSchedulers.Scheduler_InsertNearBy(nearByPlaceSearchEntity, countryId, attractionId, attractionTravelStepsId, mapsId); if (!string.IsNullOrEmpty(returnsInformation.next_page_token)) { urlString = url + "&pagetoken=" + returnsInformation.next_page_token; radiusData = webRequest.WebServiceInformation(urlString); returnsInformation = Newtonsoft.Json.JsonConvert.DeserializeObject <NearBySearchEntity>(radiusData); dALSchedulers.Scheduler_MapsLogging("LatAndLong_Init", mapsXapixFeature.MapsId, mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData, string.Empty, string.Empty, countryId, attractionId, url, false, attractionTravelStepsId); if (returnsInformation.results != null && returnsInformation.results.Count > 0) { InsertSearchResult(returnsInformation, countryId, url, longitude, latitude, attractionId, attractionTravelStepsId, mapsId, mapsXapixFeature); } } }
private void NearestLocationApiCall(string latitude, string longitude, bool isCityInfo, MasterCityDTO masterCityDto, List <GoogleTypes> googleType, int countryId, int attractionId, MapsXAPIXFeature mapsXapixFeature, string attractionName, int attractionTravelStepsId = 0) { string radiusData = string.Empty; string url = string.Empty; if (!string.IsNullOrEmpty(latitude) && !string.IsNullOrEmpty(longitude)) { foreach (var googleTypes in googleType) { try { radiusData = string.Empty; url = string.Empty; switch (mapsXapixFeature.MapsId) { //google case 1: { url = mapsXapixFeature.API + latitude + "," + longitude + "&radius=25000&key=" + mapsXapixFeature.apiKeyOrapiId; if (!string.IsNullOrEmpty(googleTypes.TypeName)) { url = url + "&type=" + googleTypes.TypeName; } radiusData = webRequest.WebServiceInformation(url); var returnsInformation = JsonConvert.DeserializeObject <NearBySearchEntity>( radiusData); if (returnsInformation != null && returnsInformation.results.Any()) { if (isCityInfo) { dALSchedulers.UpdateCityNearestLocationDont(masterCityDto .CityId); } InsertSearchResult(returnsInformation, countryId, url, longitude, latitude, attractionId, attractionTravelStepsId, mapsXapixFeature.MapsId, mapsXapixFeature); dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall", mapsXapixFeature.MapsId, mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData, string.Empty, string.Empty, countryId, attractionId, url, false, attractionTravelStepsId); } else { dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall", mapsXapixFeature.MapsId, mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData, string.Empty, string.Empty, countryId, attractionId, url, true, attractionTravelStepsId); } break; } //locationiq case 2: { url = mapsXapixFeature.API + "key=" + mapsXapixFeature.apiKeyOrapiId + "&format=json" + "&lat=" + latitude + "&lon=" + longitude + "&tag=" + googleTypes.TypeName; radiusData = webRequest.WebServiceInformation(url); var returnsInformation = JsonConvert .DeserializeObject <List <NearBy> >(radiusData); if (returnsInformation != null && returnsInformation.Any()) { var result = returnsInformation.Where(x => !string.IsNullOrEmpty(x.name)).Select( y => new ResultsList { geometry = new geometryList { location = new locationList { lat = y.lat, lng = y.lon } }, name = y.name, types = (new List <string>() { googleTypes.TypeName }).ToArray() }).ToList(); InsertSearchResult(new NearBySearchEntity { results = result }, countryId, url, longitude, latitude, attractionId, attractionTravelStepsId, mapsXapixFeature.MapsId, mapsXapixFeature); dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall", mapsXapixFeature.MapsId, mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, string.Empty, string.Empty, string.Empty, countryId, attractionId, url, false, attractionTravelStepsId); } else { dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall", mapsXapixFeature.MapsId, mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData, string.Empty, string.Empty, countryId, attractionId, url, true, attractionTravelStepsId); } //Every request after taking a break of one second Thread.Sleep(1000); break; } case 3: { if (!string.IsNullOrEmpty(attractionName)) { url = mapsXapixFeature.API + "at=" + latitude + "," + longitude + "&q=" + attractionName + "&app_id=" + mapsXapixFeature.apiKeyOrapiId + "&app_code=" + mapsXapixFeature.apiCode; radiusData = webRequest.WebServiceInformation(url); var returnsInformation = JsonConvert .DeserializeObject <BusinessEntites.Scheduler.here.NearBy>(radiusData); } break; } } } catch (Exception ex) { dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall", mapsXapixFeature.MapsId, mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData, ex.Message, ex.StackTrace, countryId, attractionId, url, true, attractionTravelStepsId); if (ex.Message == "The remote server returned an error: (429) Too Many Requests.") { Thread.Sleep(1000 * 60); } } } } }