Exemplo n.º 1
0
        public static Town FromIpAddress(string ip)
        {
            GridRef maxmindLocation = MaxmindUtil.GetLocation(ip);

            if (maxmindLocation == null)
            {
                return(null);
            }
            else
            {
                return(Town.FromGridRef(maxmindLocation));
            }
        }
Exemplo n.º 2
0
        public static Town FromGridRef(GridRef input)
        {
            if (input == null)
            {
                return(null);
            }

            Sproc sp = new Sproc("Geonames_S_FindName", _database);

            sp.Parameters.Add("@Latitude", SqlDbType.Float).Value  = input.Latitude;
            sp.Parameters.Add("@Longitude", SqlDbType.Float).Value = input.Longitude;

            return(sp.ExecuteObject <IPlace>(FromDataRecord) as Town);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the distance from the specified GridRef in metres
        /// </summary>
        /// <param name="start">Another GridRef</param>
        /// <returns>A distance in metres</returns>
        public double DistanceInMetresFrom(GridRef start)
        {
            // Use OsRef if both have canonical values...
            if (_canonicalOsRef && start._canonicalOsRef)
            {
                return(_osRef.DistanceInMetresFrom(start._osRef));
            }
            // ... otherwise use LatLng if both have canonical values...
            else if (_canonicalLatLng && start._canonicalLatLng)
            {
                return(_latLng.DistanceInMetresFrom(start._latLng));
            }

            // ...otherwise go back to OsRef. One location will have to be converted, so we may as well use the simpler distance calculation.
            return(_osRef.DistanceInMetresFrom(start._osRef));
        }
        /// <summary>
        /// Returns a grid reference for the postcode, or null if none can be determined.
        /// </summary>
        /// <returns></returns>
        public GridRef GetLocation()
        {
            if (_gridRef == null)
            {
                // If we have a complete postcode, get a location from Capscan
                if (_isValid)
                {
                    com.bauerhosting.postcodes.GridRef g = _service.GetLocation(_value, _siteName);
                    if (g != null)
                    {
                        _gridRef = new GridRef(g.Easting, g.Northing, g.Latitude, g.Longitude);
                    }
                    //_gridRef = CapScanUtil.GetLocation( _value );
                }

                // If this is a Belfast postcode and Capscan reports that it is east of Douglas, something
                // has gone wrong. Throw the grid ref away and get one from the database.
                if (_gridRef != null && _outcode != null &&
                    _outcode.StartsWith("BT") && _gridRef.Easting > 237800)
                {
                    _gridRef = null;
                }

                // If we have an outcode but no grid ref, get a approximate location from the database
                if (_gridRef == null && _outcode != null)
                {
                    Sproc sp = new Sproc("PostcodeDistrict_Select", "ParkersMeta");
                    sp.Parameters.Add("@Postcode", SqlDbType.VarChar, 10).Value = _outcode;
                    using (SqlDataReader dr = sp.ExecuteReader())
                    {
                        if (dr.HasRows && dr.Read())
                        {
                            _gridRef = new GridRef((int)dr["Easting"], (int)dr["Northing"], (double)dr["Latitude"], (double)dr["Longitude"]);
                        }
                        else
                        {
                            _gridRef = null;
                        }
                    }
                }
            }

            return(_gridRef);
        }
 public static GeonameLocation FromGridRef(GridRef gridRef)
 {
     return(new GeonameLocation());
 }
Exemplo n.º 6
0
 /// <summary>
 /// Calculates the distance from the specified GridRef in miles
 /// </summary>
 /// <param name="start">Another GridRef</param>
 /// <returns>A distance in miles</returns>
 public double DistanceInMilesFrom(GridRef start)
 {
     return(this.DistanceInMetresFrom(start) / _metresPerMile);
 }