Beispiel #1
0
        /// <summary>
        /// Geocodes the specified address.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="resultMsg">The result MSG.</param>
        /// <returns>
        /// True/False value of whether the address was geocoded successfully
        /// </returns>
        public override VerificationResult Verify(Rock.Model.Location location, out string resultMsg)
        {
            VerificationResult result = VerificationResult.None;

            resultMsg = string.Empty;

            string licenseKey = GetAttributeValue("LicenseKey");

            var         client         = new DOTSGeoCoderSoapClient();
            Location_V3 location_match = client.GetBestMatch_V3(
                string.Format("{0} {1}",
                              location.Street1,
                              location.Street2),
                location.City,
                location.State,
                location.PostalCode,
                licenseKey);

            resultMsg = location_match.Level;

            if (location_match.Level == "S" || location_match.Level == "P")
            {
                double latitude  = double.Parse(location_match.Latitude);
                double longitude = double.Parse(location_match.Longitude);
                if (location.SetLocationPointFromLatLong(latitude, longitude))
                {
                    result = VerificationResult.Geocoded;
                }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Geocodes the specified address.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="result">The ServiceObjects result.</param>
        /// <returns>
        /// True/False value of whether the address was standardized succesfully
        /// </returns>
        public override bool Geocode(Rock.Model.Location location, out string result)
        {
            if (location != null)
            {
                string licenseKey = GetAttributeValue("LicenseKey");

                var         client         = new DOTSGeoCoderSoapClient();
                Location_V3 location_match = client.GetBestMatch_V3(
                    string.Format("{0} {1}",
                                  location.Street1,
                                  location.Street2),
                    location.City,
                    location.State,
                    location.Zip,
                    licenseKey);

                result = location_match.Level;

                if (location_match.Level == "S" || location_match.Level == "P")
                {
                    double latitude  = double.Parse(location_match.Latitude);
                    double longitude = double.Parse(location_match.Longitude);
                    location.SetLocationPointFromLatLong(latitude, longitude);

                    return(true);
                }
            }
            else
            {
                result = "Null Address";
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Geocodes the specified address.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="result">The ServiceObjects result.</param>
        /// <returns>
        /// True/False value of whether the address was standardized succesfully
        /// </returns>
        public override bool Geocode(Rock.CRM.Address address, out string result)
        {
            if (address != null)
            {
                string licenseKey = AttributeValue("LicenseKey");

                var         client   = new DOTSGeoCoderSoapClient();
                Location_V3 location = client.GetBestMatch_V3(
                    string.Format("{0} {1}",
                                  address.Street1,
                                  address.Street2),
                    address.City,
                    address.State,
                    address.Zip,
                    licenseKey);

                result = location.Level;

                if (location.Level == "S" || location.Level == "P")
                {
                    address.Latitude  = double.Parse(location.Latitude);
                    address.Longitude = double.Parse(location.Longitude);

                    return(true);
                }
            }
            else
            {
                result = "Null Address";
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Geocodes the specified address.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="reVerify">Should location be reverified even if it has already been successfully verified</param>
        /// <param name="result">The result code unique to the service.</param>
        /// <returns>
        /// True/False value of whether the address was geocoded successfully
        /// </returns>
        public override bool VerifyLocation(Rock.Model.Location location, bool reVerify, out string result)
        {
            bool verified = false;

            result = string.Empty;

            // Only verify if location is valid, has not been locked, and
            // has either never been attempted or last attempt was in last 30 secs (prev active service failed) or reverifying
            if (location != null &&
                !(location.IsGeoPointLocked ?? false) &&
                (
                    !location.GeocodeAttemptedDateTime.HasValue ||
                    location.GeocodeAttemptedDateTime.Value.CompareTo(RockDateTime.Now.AddSeconds(-30)) > 0 ||
                    reVerify
                ))
            {
                string licenseKey = GetAttributeValue("LicenseKey");

                var         client         = new DOTSGeoCoderSoapClient();
                Location_V3 location_match = client.GetBestMatch_V3(
                    string.Format("{0} {1}",
                                  location.Street1,
                                  location.Street2),
                    location.City,
                    location.State,
                    location.PostalCode,
                    licenseKey);

                result = location_match.Level;

                location.GeocodeAttemptedServiceType = "ServiceObjects";
                location.GeocodeAttemptedDateTime    = RockDateTime.Now;
                location.GeocodeAttemptedResult      = result;

                if (location_match.Level == "S" || location_match.Level == "P")
                {
                    double latitude  = double.Parse(location_match.Latitude);
                    double longitude = double.Parse(location_match.Longitude);
                    location.SetLocationPointFromLatLong(latitude, longitude);
                    location.GeocodedDateTime = RockDateTime.Now;
                    verified = true;
                }
            }

            return(verified);
        }