public static async Task <ElevationLocation> FindOrUpdateInDatabase(ulong c, IElevationService service) { var cellId = new S2CellId(c); var latlng = cellId.ToLatLng(); return(await FindOrUpdateInDatabase(latlng.LatDegrees, latlng.LngDegrees, service).ConfigureAwait(false)); }
public ElevationLocation(ulong c) { var cellId = new S2CellId(c); var latlng = cellId.ToLatLng(); Init(latlng.LatDegrees, latlng.LngDegrees); }
public GeoLocation(ulong capturedCellId) { var cellId = new S2CellId(capturedCellId); var latlng = cellId.ToLatLng(); Init(latlng.LatDegrees, latlng.LngDegrees); }
public static async Task <GeoLocation> FindOrUpdateInDatabase(ulong capturedCellId) { var cellId = new S2CellId(capturedCellId); var latlng = cellId.ToLatLng(); return(await FindOrUpdateInDatabase(latlng.LatDegrees, latlng.LngDegrees)); }
public void Test_S2CellId_Inverses() { // Check the conversion of random leaf cells to S2LatLngs and back. for (int i = 0; i < 200000; ++i) { S2CellId id = S2Testing.GetRandomCellId(S2.kMaxCellLevel); Assert.True(id.IsLeaf()); Assert.Equal(S2.kMaxCellLevel, id.Level()); S2LatLng center = id.ToLatLng(); Assert.Equal(id.Id, new S2CellId(center).Id); } }
private string ReverseGeoCodeCapturedCellIdToLocation(ulong capturedCellId) { var cellId = new S2CellId(capturedCellId); var latlng = cellId.ToLatLng(); string location; // Check cache for location. bool success = PokemonListModel.LocationsCache.TryGetValue(this.PokemonData.CapturedCellId, out location); if (success) { return(location); } GoogleGeocoder geocoder = new GoogleGeocoder(); var addresses = geocoder.ReverseGeocode(new Geocoding.Location(latlng.LatDegrees, latlng.LngDegrees)); GoogleAddress addr = addresses.Where(a => !a.IsPartialMatch).FirstOrDefault(); if (addr != null && addr[GoogleAddressType.Country] != null) { if (addr[GoogleAddressType.Locality] != null) { location = $"{addr[GoogleAddressType.Locality].LongName}, {addr[GoogleAddressType.Country].LongName}"; } else if (addr[GoogleAddressType.AdministrativeAreaLevel1] != null) { location = $"{addr[GoogleAddressType.AdministrativeAreaLevel1].LongName}, {addr[GoogleAddressType.Country].LongName}"; } else if (addr[GoogleAddressType.AdministrativeAreaLevel2] != null) { location = $"{addr[GoogleAddressType.AdministrativeAreaLevel2].LongName}, {addr[GoogleAddressType.Country].LongName}"; } else if (addr[GoogleAddressType.AdministrativeAreaLevel3] != null) { location = $"{addr[GoogleAddressType.AdministrativeAreaLevel3].LongName}, {addr[GoogleAddressType.Country].LongName}"; } else { location = $"{addr[GoogleAddressType.Country].LongName}"; } // Add to cache PokemonListModel.LocationsCache.Add(this.PokemonData.CapturedCellId, location); } else { location = $"{latlng.LatDegrees}, {latlng.LngDegrees}"; } return(location); }
public static double[] GetLatLng(ulong cellid) { var s2cell = new S2CellId(cellid); return(new [] { s2cell.ToLatLng().LatDegrees, s2cell.ToLatLng().LngDegrees }); }