Exemplo n.º 1
0
        public GeocodingResponse LookupByAddressInBounds(string address, GeocodingGeometryLocationBounds bounds, bool strict = false)
        {
            var url = GeocodingUrl +
                      "?sensor=" + _deviceHasGpsSensor.ToString().ToLowerInvariant() +
                      "&address=" + HttpUtility.UrlEncode(address) +
                      string.Format("&bounds={0},{1}|{2},{3}",
                                    bounds.Southwest.Latitude, bounds.Southwest.Longitude,
                                    bounds.Northeast.Latitude, bounds.Northeast.Longitude);

            var result = GetObject <GeocodingResponse>(url);

            if (!strict)
            {
                return(result);
            }

            result.Results = result.Results
                             .Where(x => LocationIsWithinBounds(x.Geometry.Location, bounds))
                             .ToArray();
            return(result);
        }
Exemplo n.º 2
0
 private static bool LocationIsWithinBounds(GeocodingGeometryLocation location, GeocodingGeometryLocationBounds bounds)
 {
     if (location.Latitude < bounds.Southwest.Latitude)
     {
         return(false);
     }
     if (location.Latitude > bounds.Northeast.Latitude)
     {
         return(false);
     }
     if (location.Longitude < bounds.Southwest.Longitude)
     {
         return(false);
     }
     if (location.Longitude > bounds.Northeast.Longitude)
     {
         return(false);
     }
     return(true);
 }