/// <summary> /// Returns new or cached location guess based on client IP address /// </summary> /// <returns></returns> public LocationLookupResult PerformLocationGuess(bool includeCountryID) { LocationLookupResult locationGuess = null; if (Session["locationGuess"] != null) { locationGuess = (LocationLookupResult)Session["locationGuess"]; } if (locationGuess == null || (locationGuess != null && (locationGuess.Country_Code == null || includeCountryID && locationGuess.CountryID == 0))) { var clientIP = Request.ServerVariables["REMOTE_ADDR"]; locationGuess = GeocodingHelper.GetLocationFromIP_FreegeoIP(clientIP); if (includeCountryID) { var country = new ReferenceDataManager().GetCountryByISO(locationGuess.Country_Code); if (country != null) { locationGuess.CountryID = country.ID; } } Session["locationGuess"] = locationGuess; } return(locationGuess); }
private void OutputGeocodingResult(IOutputProvider outputProvider, HttpContext context, APIRequestParams filter) { GeocodingResult result = null; //get or get and cache result if (HttpContext.Current.Cache["Geocoding_" + filter.HashKey] != null && filter.EnableCaching) { result = (GeocodingResult)HttpContext.Current.Cache["Geocoding_" + filter.HashKey]; } else { var geocoder = new GeocodingHelper(); geocoder.IncludeExtendedData = true; //result = geocoder.GeolocateAddressInfo_OSM(filter.Address); result = geocoder.GeolocateAddressInfo_Google(filter.Address); HttpContext.Current.Cache.Add("Geocoding_" + filter.HashKey, result, null, Cache.NoAbsoluteExpiration, new TimeSpan(1, 0, 0), CacheItemPriority.Normal, null); } //send API response if (filter.IsEnvelopedResponse) { var responseEnvelope = new APIResponseEnvelope(); responseEnvelope.Data = result; outputProvider.GetOutput(context.Response.OutputStream, responseEnvelope, filter); } else { outputProvider.GetOutput(context.Response.OutputStream, result, filter); } }
public void AddHome(AddHomeBindingModel home) { var homeToAdd = AutoMapper.Mapper.Map <AddHomeBindingModel, Home>(home); if (home.ProfilePicture != null) { var profilePicture = PictureHelper.ConvertToBytes(home.ProfilePicture); string linkToProfilePicture = String.Empty; using (var dbx = new DropboxClient(DropboxHelper.AccessToken)) { linkToProfilePicture = DropboxHelper.Upload(dbx, "/Homes/" + home.Name, "profile.png", profilePicture).ToString(); } homeToAdd.ProfilePicture = linkToProfilePicture; } else { homeToAdd.ProfilePicture = "/Defaults/home.png"; } GeocodingHelper.SetLocation(homeToAdd.Location); homeToAdd.PostedDate = DateTime.Now; repository.Insert(homeToAdd); this.repository.Commit(); }
private void OutputGeocodingResult(IOutputProvider outputProvider, HttpContext context, APIRequestParams filter) { GeocodingResult result = null; //get or get and cache result /*if (context.Cache["Geocoding_" + filter.HashKey] != null && filter.EnableCaching) * { * result = (GeocodingResult)context.Cache["Geocoding_" + filter.HashKey]; * } * else * { * * * //context.Cache.Add("Geocoding_" + filter.HashKey, result, null, Cache.NoAbsoluteExpiration, new TimeSpan(1, 0, 0), CacheItemPriority.Normal, null); * }*/ var geocoder = new GeocodingHelper(_settings); geocoder.IncludeExtendedData = false; if (!string.IsNullOrEmpty(filter.Address)) { result = geocoder.GeolocateAddressInfo_MapquestOSM(filter.Address); } else if (filter.Latitude != null && filter.Longitude != null) { result = geocoder.ReverseGecode_MapquestOSM((double)filter.Latitude, (double)filter.Longitude, new ReferenceDataManager()); if (!result.ResultsAvailable) { result = geocoder.ReverseGecode_OSM((double)filter.Latitude, (double)filter.Longitude, new ReferenceDataManager()); } } //send API response if (filter.IsEnvelopedResponse) { var responseEnvelope = new APIResponseEnvelope(); responseEnvelope.Data = result; outputProvider.GetOutput(context, context.Response.Body, responseEnvelope, filter); } else { outputProvider.GetOutput(context, context.Response.Body, result, filter); } }
private async void HandleOnGoogleMapClick(object sender, GoogleMap.MapClickEventArgs e) { if (!RequestExternalStoragePermissionIfNecessary(RC_WRITE_EXTERNAL_STORAGE_PERMISSION)) { return; } Address address = await GeocodingHelper.ReverseGeocodeCurrentLocation(e.Point, this); var marker = new MarkerInfo { Longtitude = e.Point.Longitude, Latitude = e.Point.Latitude, Address = address == null ? string.Empty : $"{address.CountryName} {address.AdminArea}", LastModData = DateTime.Now }; string markerString = JsonConvert.SerializeObject(marker); App.Locator.MainViewModel.CreateNewMarkerCommand.Execute(markerString); }
public async Task <ActionResult> Index(POIBrowseModel filter) { if (filter?.ReferenceData == null) { if (filter == null) { filter = new POIBrowseModel(); filter.ShowAdvancedOptions = true; } filter.ReferenceData = await GetCoreReferenceDataAsync(); } var cpManager = new API.Common.POIManager(); //dropdown selections of -1 represent an intended null selection, fix this by nulling relevant items filter.CountryIDs = this.ConvertNullableSelection(filter.CountryIDs); filter.LevelIDs = this.ConvertNullableSelection(filter.LevelIDs); filter.ConnectionTypeIDs = this.ConvertNullableSelection(filter.ConnectionTypeIDs); filter.OperatorIDs = this.ConvertNullableSelection(filter.OperatorIDs); filter.StatusTypeIDs = this.ConvertNullableSelection(filter.StatusTypeIDs); filter.UsageTypeIDs = this.ConvertNullableSelection(filter.UsageTypeIDs); filter.DataProviderIDs = this.ConvertNullableSelection(filter.DataProviderIDs); filter.IncludeComments = true; if (IsRequestByRobot) { //force mirror db when browser is a robot filter.AllowMirrorDB = true; filter.AllowDataStoreDB = false; } if (!String.IsNullOrWhiteSpace(filter.Country)) { //TODO: cache country id lookup using (var refData = new OCM.API.Common.ReferenceDataManager()) { var countrySelected = refData.GetCountryByName(filter.Country); if (countrySelected != null) { filter.CountryIDs = new int[] { countrySelected.ID }; } } } else { //default to UK // if (filter.CountryIDs == null) filter.CountryIDs = new int[] { 1 }; } filter.MaxResults = 100; if (!String.IsNullOrWhiteSpace(filter.SearchLocation)) { if (filter.SearchLocation.ToUpper().StartsWith("OCM-")) { filter.SearchLocation = filter.SearchLocation.Replace("OCM-", ""); } if (filter.SearchLocation.ToUpper().StartsWith("OCM")) { filter.SearchLocation = filter.SearchLocation.Replace("OCM", ""); } if (IsNumeric(filter.SearchLocation.Trim())) { int poiID = -1; //treat numbers as OCM ref if (int.TryParse(filter.SearchLocation.Trim(), out poiID)) { filter.ChargePointIDs = new int[] { poiID }; } } else { //attempt to geocode var geocode = new GeocodingHelper(_settings); string searchCountryName = null; if (filter.CountryIDs != null && filter.CountryIDs.Count() > 0) { var searchCountry = filter.ReferenceData.Countries.FirstOrDefault(c => c.ID == filter.CountryIDs[0]); searchCountryName = searchCountry.Title; } API.Common.Model.Extended.GeocodingResult position = null; // FIXME: geocoding is disabled, find an laternative service to use //geocode.GeolocateAddressInfo_Google(filter.SearchLocation.Trim() + (searchCountryName != null ? ", " + searchCountryName : "")); if (filter.SearchLocation.Contains(",")) { var vals = filter.SearchLocation.Split(','); if (IsNumeric(vals[0]) && IsNumeric(vals[1])) { position = new API.Common.Model.Extended.GeocodingResult { Latitude = double.Parse(vals[0]), Longitude = double.Parse(vals[1]) }; } } if (position != null) { filter.Latitude = position.Latitude; filter.Longitude = position.Longitude; if (filter.Distance == null) { filter.Distance = 50; } filter.DistanceUnit = API.Common.Model.DistanceUnit.Miles; //TODO: distance unit KM //if (distanceunit == "km") searchfilters.DistanceUnit = API.Common.Model.DistanceUnit.KM; ViewBag.FormattedAddress = position.Address ?? ""; } } } filter.POIList = (await cpManager.GetPOIListAsync((OCM.API.Common.APIRequestParams)filter, filter.ReferenceData)).ToList(); return(View(filter)); }
// GET: /POI/ public ActionResult Index(POIBrowseModel filter) { if (filter == null) { filter = new POIBrowseModel(); filter.ShowAdvancedOptions = true; } var cpManager = new API.Common.POIManager(); //dropdown selections of -1 represent an intended null selection, fix this by nulling relevant items filter.CountryIDs = this.ConvertNullableSelection(filter.CountryIDs); filter.LevelIDs = this.ConvertNullableSelection(filter.LevelIDs); filter.ConnectionTypeIDs = this.ConvertNullableSelection(filter.ConnectionTypeIDs); filter.OperatorIDs = this.ConvertNullableSelection(filter.OperatorIDs); filter.StatusTypeIDs = this.ConvertNullableSelection(filter.StatusTypeIDs); filter.UsageTypeIDs = this.ConvertNullableSelection(filter.UsageTypeIDs); filter.DataProviderIDs = this.ConvertNullableSelection(filter.DataProviderIDs); filter.IncludeComments = true; if (IsRequestByRobot) { //force mirror db when browser is a robot filter.AllowMirrorDB = true; } if (!String.IsNullOrWhiteSpace(filter.Country)) { //TODO: cache country id lookup var countrySelected = new OCM.API.Common.ReferenceDataManager().GetCountryByName(filter.Country); if (countrySelected != null) { filter.CountryIDs = new int[] { countrySelected.ID }; } } else { //default to UK // if (filter.CountryIDs == null) filter.CountryIDs = new int[] { 1 }; } filter.MaxResults = 100; if (!String.IsNullOrWhiteSpace(filter.SearchLocation)) { if (filter.SearchLocation.ToUpper().StartsWith("OCM-")) { filter.SearchLocation = filter.SearchLocation.Replace("OCM-", ""); } if (filter.SearchLocation.ToUpper().StartsWith("OCM")) { filter.SearchLocation = filter.SearchLocation.Replace("OCM", ""); } if (IsNumeric(filter.SearchLocation.Trim())) { int poiID = -1; //treat numbers as OCM ref if (int.TryParse(filter.SearchLocation.Trim(), out poiID)) { filter.ChargePointIDs = new int[] { poiID }; } } else { //attempt to geocode var geocode = new GeocodingHelper(); string searchCountryName = null; if (filter.CountryIDs != null && filter.CountryIDs.Count() > 0) { var searchCountry = filter.ReferenceData.Countries.FirstOrDefault(c => c.ID == filter.CountryIDs[0]); searchCountryName = searchCountry.Title; } var position = geocode.GeolocateAddressInfo_Google(filter.SearchLocation.Trim() + (searchCountryName != null ? ", " + searchCountryName : "")); if (position != null) { filter.Latitude = position.Latitude; filter.Longitude = position.Longitude; if (filter.Distance == null) { filter.Distance = 50; } filter.DistanceUnit = API.Common.Model.DistanceUnit.Miles; //TODO: distance unit KM //if (distanceunit == "km") searchfilters.DistanceUnit = API.Common.Model.DistanceUnit.KM; ViewBag.FormattedAddress = position.Address; } } } filter.POIList = cpManager.GetChargePoints((OCM.API.Common.APIRequestParams)filter); return(View(filter)); }
// // GET: /POI/ public ActionResult Index(POIBrowseModel filter) { if (filter == null) { filter = new POIBrowseModel(); filter.ShowAdvancedOptions = true; } var cpManager = new API.Common.POIManager(); //dropdown selections of -1 represent an intended null selection, fix this by nulling relevant items filter.CountryIDs = this.ConvertNullableSelection(filter.CountryIDs); filter.LevelIDs = this.ConvertNullableSelection(filter.LevelIDs); filter.ConnectionTypeIDs = this.ConvertNullableSelection(filter.ConnectionTypeIDs); filter.OperatorIDs = this.ConvertNullableSelection(filter.OperatorIDs); filter.StatusTypeIDs = this.ConvertNullableSelection(filter.StatusTypeIDs); filter.UsageTypeIDs = this.ConvertNullableSelection(filter.UsageTypeIDs); filter.DataProviderIDs = this.ConvertNullableSelection(filter.DataProviderIDs); filter.IncludeComments = true; if (IsRequestByRobot) { //force mirror db when browser is a robot filter.AllowMirrorDB = true; } if (!String.IsNullOrWhiteSpace(filter.Country)) { //TODO: cache country id lookup var countrySelected = new OCM.API.Common.ReferenceDataManager().GetCountryByName(filter.Country); if (countrySelected != null) { filter.CountryIDs = new int[] { countrySelected.ID }; } } else { //default to UK // if (filter.CountryIDs == null) filter.CountryIDs = new int[] { 1 }; } filter.MaxResults = 100; if (!String.IsNullOrWhiteSpace(filter.SearchLocation)) { if (filter.SearchLocation.ToUpper().StartsWith("OCM-")) filter.SearchLocation = filter.SearchLocation.Replace("OCM-", ""); if (filter.SearchLocation.ToUpper().StartsWith("OCM")) filter.SearchLocation = filter.SearchLocation.Replace("OCM", ""); if (IsNumeric(filter.SearchLocation.Trim())) { int poiID = -1; //treat numbers as OCM ref if (int.TryParse(filter.SearchLocation.Trim(), out poiID)) { filter.ChargePointIDs = new int[] { poiID }; } } else { //attempt to geocode var geocode = new GeocodingHelper(); string searchCountryName = null; if (filter.CountryIDs != null && filter.CountryIDs.Count() > 0) { var searchCountry = filter.ReferenceData.Countries.FirstOrDefault(c => c.ID == filter.CountryIDs[0]); searchCountryName = searchCountry.Title; } var position = geocode.GeolocateAddressInfo_Google(filter.SearchLocation.Trim() + (searchCountryName != null ? ", " + searchCountryName : "")); if (position != null) { filter.Latitude = position.Latitude; filter.Longitude = position.Longitude; if (filter.Distance == null) filter.Distance = 50; filter.DistanceUnit = API.Common.Model.DistanceUnit.Miles; //TODO: distance unit KM //if (distanceunit == "km") searchfilters.DistanceUnit = API.Common.Model.DistanceUnit.KM; ViewBag.FormattedAddress = position.Address; } } } filter.POIList = cpManager.GetChargePoints((OCM.API.Common.APIRequestParams)filter); return View(filter); }
private void OutputGeocodingResult(IOutputProvider outputProvider, HttpContext context, APIRequestParams filter) { GeocodingResult result = null; //get or get and cache result if (HttpContext.Current.Cache["Geocoding_" + filter.HashKey] != null && filter.EnableCaching) { result = (GeocodingResult)HttpContext.Current.Cache["Geocoding_" + filter.HashKey]; } else { var geocoder = new GeocodingHelper(); geocoder.IncludeExtendedData = true; //result = geocoder.GeolocateAddressInfo_OSM(filter.Address); result = geocoder.GeolocateAddressInfo_Google(filter.Address); HttpContext.Current.Cache.Add("Geocoding_" + filter.HashKey, result, null, Cache.NoAbsoluteExpiration, new TimeSpan(1, 0, 0), CacheItemPriority.Normal, null); } //send API response if (filter.IsEnvelopedResponse) { var responseEnvelope = new APIResponseEnvelope(); responseEnvelope.Data = result; outputProvider.GetOutput(context.Response.OutputStream, responseEnvelope, filter); } else { outputProvider.GetOutput(context.Response.OutputStream, result, filter); } }