コード例 #1
0
        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));
        }
コード例 #2
0
        public ElevationLocation(ulong c)
        {
            var cellId = new S2CellId(c);
            var latlng = cellId.ToLatLng();

            Init(latlng.LatDegrees, latlng.LngDegrees);
        }
コード例 #3
0
        public GeoLocation(ulong capturedCellId)
        {
            var cellId = new S2CellId(capturedCellId);
            var latlng = cellId.ToLatLng();

            Init(latlng.LatDegrees, latlng.LngDegrees);
        }
コード例 #4
0
        public static async Task <GeoLocation> FindOrUpdateInDatabase(ulong capturedCellId)
        {
            var cellId = new S2CellId(capturedCellId);
            var latlng = cellId.ToLatLng();

            return(await FindOrUpdateInDatabase(latlng.LatDegrees, latlng.LngDegrees));
        }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
        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);
        }
コード例 #7
0
        public static double[] GetLatLng(ulong cellid)
        {
            var s2cell = new S2CellId(cellid);

            return(new [] { s2cell.ToLatLng().LatDegrees, s2cell.ToLatLng().LngDegrees });
        }