private void Awake() { var statesDataProvider = new JsonDataProvider(_statesJson.text); var countriesDataProvider = new JsonDataProvider(_countriesJson.text); _geocoderService = new CountryReverseGeocodeService(countriesDataProvider, statesDataProvider); }
public static List <GroupedTweetsGeo> TweetsGeoCode() { CountryReverseGeocodeService _service = new CountryReverseGeocodeService(); List <GroupedTweetsGeo> groupedTweets = new List <GroupedTweetsGeo>(); using (var context = new AppDbContext()) { var tweets = context.TweetsRaw .Include(x => x.TweetSentiment) .Include(x => x.User) .ThenInclude(x => x.GeoUsers).ToList(); foreach (var t in tweets.Where(x => x.User.GeoUsers != null && x.User.GeoUsers.Count > 0)) { GeoLocation location = new GeoLocation(); try { location = new GeoLocation { Longitude = t.User.GeoUsers[0].Lon, Latitude = t.User.GeoUsers[0].Lat }; } catch (Exception) { } var info = _service.FindCountry(location); if (info != null && !string.IsNullOrEmpty(info.Name) && info.Name == "Italy") { try { var fromDate = new DateTime(t.CreatedAt.Year, t.CreatedAt.Month, t.CreatedAt.Day, t.CreatedAt.Hour, 0, 0); if (groupedTweets.Count(x => x.FromDate == fromDate) == 0) { groupedTweets.Add(new GroupedTweetsGeo() { FromDate = fromDate }); } var geoTweet = new TweetsGeoCode() { CreatedAt = t.CreatedAt, Text = t.Text, Sentiment = t.TweetSentiment == null?tweets.First(x => x.Id == t.RetweetedStatusId).TweetSentiment.Sentiment.GetDescription() : t.TweetSentiment.Sentiment.GetDescription(), UserProfileName = t.User.Name, UserScreenName = t.User.ScreenName, Latitude = location.Latitude, Longitude = location.Longitude, PositiveScore = t.TweetSentiment == null?tweets.First(x => x.Id == t.RetweetedStatusId).TweetSentiment.PositiveScore : t.TweetSentiment.PositiveScore, NegativeScore = t.TweetSentiment == null?tweets.First(x => x.Id == t.RetweetedStatusId).TweetSentiment.NegativeScore : t.TweetSentiment.NegativeScore, NeutralScore = t.TweetSentiment == null?tweets.First(x => x.Id == t.RetweetedStatusId).TweetSentiment.NeutralScore : t.TweetSentiment.NeutralScore, }; groupedTweets.Where(x => x.FromDate == fromDate).FirstOrDefault().Tweets.Add(geoTweet); } catch (Exception ex) { } } } } return(groupedTweets); }
public CountryLocator(CountryReverseGeocodeService reverseGeocodeService) { this.reverseGeocodeService = reverseGeocodeService; iso3ToIso2Mapping = new Lazy <Dictionary <string, string> >(() => CultureInfo.GetCultures(CultureTypes.SpecificCultures) .Select(ci => new RegionInfo(ci.LCID)) .GroupBy(ri => ri.ThreeLetterISORegionName) .ToDictionary(g => g.Key, g => g.First().TwoLetterISORegionName)); }
public override Task <ApiResult <GPSTruckRecordSelectDto> > Create(GPSTruckRecordDto dto, CancellationToken cancellationToken) { // Get GPS Location By Latitude and Longitude start CountryReverseGeocodeService _service = new CountryReverseGeocodeService(); GeoLocation location = new GeoLocation { Latitude = dto.Latitude, Longitude = dto.Longitude }; //GeoLocation location = new GeoLocation { Latitude = 50.064546, Longitude = 40.587502 }; var info = _service.FindCountry(location); if (info != null) { dto.CountryName = info.Name; } else { dto.CountryName = "Germany"; } // Get GPS Location By Latitude and Longitude End here double distanceInKm = 0.00, previousLatitude = 32.9697, previousLongitude = -96.80322; Guid PreviousRecordsID = Guid.NewGuid(); // Select top 1 ID, Latitude, Longitude from GPSTruckRecords Where ProcessStatus=0 and GPSDeviceID=@GPSDeviceID and Cast(varhcar,RecordDate,101)=@Today // if record found { // Set previousLatitude= tableValuedLatitude, previousLongitude=tableValuedLongitude, PreviousRecordsID=tableValuedID GPSCoordinateToDistanceConverter gPSCoordinateToDistanceConverter = new GPSCoordinateToDistanceConverter(); distanceInKm = gPSCoordinateToDistanceConverter.distance(previousLatitude, previousLongitude, dto.Latitude, dto.Longitude, 'K'); // distanceInKm = gPSCoordinateToDistanceConverter.distance(32.9697, -96.80322, 29.46786, -98.53506, 'K'); //Immediately Update the previous records // Update GPSTruckRecords set ProcessStatus=1 where ID=PreviousRecordsID } dto.Kilometer = distanceInKm; return(base.Create(dto, cancellationToken)); }
public void Setup() { _service = new CountryReverseGeocodeService(); }
public static async Task <PokemonAttributes> SearchPokemon(bool isPremium, int numberPokemon) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); _sayLog = LogManager.GetLogger("SERVIDOR COORDENADAS:"); using (var downloadData = new WebClient()) { var allPokemon = string.Empty; if (isPremium) { allPokemon = await downloadData.DownloadStringTaskAsync(ApiPremium); _sayLog.Info("Estamos carregando a lista. Aguarde..."); } else { _freeUserKey = await PokemonRaro.PokemonRaro.PokedexApiFree(); allPokemon = await downloadData.DownloadStringTaskAsync(string.Format( $"http://api.pokedex100.com/feedlink/{_freeUserKey},candies,{numberPokemon}")); } if (!CheckReceivedData(allPokemon).Result) { return(null); } var splitPokemonByLine = allPokemon.Split(new[] { "\n" }, StringSplitOptions.None).ToList(); splitPokemonByLine.RemoveAt(0); var pokemonList = new PokemonAttributes { PokemonAtribbutes = new PokemonAtribbute[splitPokemonByLine.Count] }; //Regex search settings const string regexCoordinates = @"-?\d{1,2}.\d{6},-?\d{1,3}.\d{6}"; const string regexIv = @"iv((\d{1,3})|\?)"; const string regexCP = @"cp((\d{1,4})|\?)"; const string regexTimeLeft = @"\(\d{1,2}:\d{1,2}\)"; const string regexGetNumber = @",\d{1,3},"; for (var i = 0; i < splitPokemonByLine.Count; i++) { var numPokemon = Regex.Match(splitPokemonByLine[i], regexGetNumber).Value; numPokemon = numPokemon.Remove(0, 1); numPokemon = numPokemon.Remove(numPokemon.Length - 1, 1); var nomePokemon = Enum.GetName(typeof(PokemonId), int.Parse(numPokemon)); var coordinates = Regex.Match(splitPokemonByLine[i], regexCoordinates).Value; var getLatLong = coordinates.Split(','); if (!getLatLong[0].Contains('.')) { continue; } else if (!getLatLong[1].Contains('.')) { continue; } var getIv = Regex.Match(splitPokemonByLine[i], regexIv).Value; if (string.IsNullOrEmpty(getIv)) { getIv = "?"; } else { getIv = getIv.Remove(0, 2); } var getCp = Regex.Match(splitPokemonByLine[i], regexCP).Value; if (string.IsNullOrEmpty(getCp)) { getCp = "?"; } else { getCp = getCp.Remove(0, 2); } var getTimeLeft = Regex.Match(splitPokemonByLine[i], regexTimeLeft).Value; var country = string.Empty; GeoLocation geoLoc = new GeoLocation(); geoLoc.Latitude = 0; geoLoc.Longitude = 0; try { geoLoc.Latitude = double.Parse(getLatLong[0]); geoLoc.Longitude = double.Parse(getLatLong[1]); _sayLog.Fatal($"lat: {geoLoc.Latitude} long: {geoLoc.Longitude}"); var teste = new CountryReverseGeocodeService(); country = teste.FindCountry(geoLoc).Id; country = country.ToLower(); } catch (Exception e) { _sayLog.Error(e.Message + " " + e.StackTrace); } pokemonList.PokemonAtribbutes[i] = new PokemonAtribbute(); pokemonList.PokemonAtribbutes[i].Name = nomePokemon; pokemonList.PokemonAtribbutes[i].Number = numPokemon; pokemonList.PokemonAtribbutes[i].Country = country ?? "bra"; pokemonList.PokemonAtribbutes[i].Iv = getIv; pokemonList.PokemonAtribbutes[i].Cp = getCp; pokemonList.PokemonAtribbutes[i].TimeLeft = getTimeLeft; pokemonList.PokemonAtribbutes[i].Latitude = geoLoc.Latitude; pokemonList.PokemonAtribbutes[i].Longitude = geoLoc.Longitude; } return(pokemonList); } }