Example #1
0
        /// <summary>
        /// Reverse geocoding is the process of converting geographic coordinates into a
        /// human-readable address.
        /// </summary>
        /// <param name="location">The latitude/longitude for which you wish to obtain the closest, human-readable address.</param>
        /// <param name="language">The language in which to return results.</param>
        /// <param name="addressType">One or more address types to restrict results to.</param>
        /// <param name="locationType">One or more location types to restrict results to.</param>
        /// <returns>Reverse geocoding results</returns>
        public ReverseGeocodeResultResponse ReverseGeocode(GeoCoordinatesLocation location, string language = null,
                                                           AddressTypeEnum?addressType = null, GeometryLocationType?locationType = null)
        {
            // Assign query params
            var queryParams = new QueryParams()
            {
                ["latlng"] = Converter.Location(location)
            };

            if (language != null)
            {
                queryParams["language"] = language;
            }
            if (addressType != null)
            {
                queryParams["result_type"] = Converter.EnumFlagsList(addressType.Value);
            }
            if (locationType != null)
            {
                queryParams["location_type"] = Converter.EnumFlagsList(locationType.Value);
            }

            // Get API response result
            var response = Client.APIGet <ReverseGeocodeResultResponse>("/maps/api/geocode/json", queryParams);

            // Return it
            return(response);
        }
Example #2
0
        /// <summary>
        /// Provides time offset data for locations on the surface of the earth
        /// </summary>
        /// <param name="location">The location to look up.</param>
        /// <param name="timestamp">The desired time as seconds since midnight, January 1, 1970 UTC. The Google Maps Time
        /// Zone API uses the timestamp to determine whether or not Daylight Savings should be applied. Times before 1970
        /// can be expressed as negative values.</param>
        /// <param name="language">The language in which to return results.</param>
        /// <returns>Result</returns>
        public GetTimeZoneResponse GetTimeZone(GeoCoordinatesLocation location, long timestamp, string language = null)
        {
            // Assign query params
            var queryParams = new QueryParams
            {
                ["location"]  = Converter.Location(location),
                ["timestamp"] = Converter.Time(timestamp)
            };

            // Get API response result
            var response = Client.APIGet <GetTimeZoneResponse>("/maps/api/timezone/json", queryParams);

            // Return it
            return(response);
        }
        /// <summary>
        /// Compute distance between 2 coordinates
        /// </summary>
        /// <param name="origin">Origin</param>
        /// <param name="destination">Destination</param>
        /// <param name="radius">Earth's mean radius (in meters)</param>
        /// <returns>Result distance</returns>
        public double ComputeDistanceBetween(GeoCoordinatesLocation origin, GeoCoordinatesLocation destination, double radius = 6378137)
        {
            // Get radians
            var origLatRad = origin.Latitude.ToRadians();
            var origLngRad = origin.Longitude.ToRadians();
            var destLatRad = destination.Latitude.ToRadians();
            var destLngRad = destination.Longitude.ToRadians();

            // Compute distance using Haversine formula
            var distance =
                (2 * Math.Asin(
                     Math.Sqrt(Math.Pow(Math.Sin((origLatRad - destLatRad) / 2), 2) +
                               Math.Cos(origLatRad) * Math.Cos(destLatRad) *
                               Math.Pow(Math.Sin((origLngRad - destLngRad) / 2), 2))))
                * radius;

            // Return it
            return(distance);
        }
Example #4
0
 /// <summary>
 /// Get elevation
 /// </summary>
 /// <param name="location">Location</param>
 /// <returns>Result</returns>
 public GetElevationResponse GetElevations(GeoCoordinatesLocation location)
 {
     return(GetElevations(new [] { location }));
 }
Example #5
0
 /// <summary>
 /// Provides time offset data for locations on the surface of the earth
 /// </summary>
 /// <param name="location">The location to look up.</param>
 /// <param name="forDate">The date to determine whether or not Daylight Savings should be applied</param>
 /// <param name="language">The language in which to return results.</param>
 /// <returns>Result</returns>
 public GetTimeZoneResponse GetTimeZone(GeoCoordinatesLocation location, DateTime forDate, string language = null)
 {
     // Call overload with converted target date
     return(GetTimeZone(location, forDate.SecondsSinceEpoch(), language));
 }
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="southwest">South west corner of the viewport bounding box</param>
 /// <param name="northEast">North east corner of the viewport bounding box</param>
 public ViewportBoundingBox(GeoCoordinatesLocation southwest, GeoCoordinatesLocation northEast)
 {
     Southwest = southwest;
     NorthEast = northEast;
 }
 /// <summary>
 /// Create a new instance
 /// </summary>
 public ViewportBoundingBox()
 {
     NorthEast = new GeoCoordinatesLocation();
     Southwest = new GeoCoordinatesLocation();
 }