Exemplo n.º 1
0
        public CoordinateResult GetCoordinateWithGeocode(string address, ServiceResultTypes resultType = ServiceResultTypes.street_address)
        {
            var result = new CoordinateResult()
            {
                Coordinate = new Coordinate(), Status = ServiceResultStatus.NOT_DEFINED
            };

            if (!CheckAddress(address) || !CheckFilterAddress(address))
            {
                result.Status = ServiceResultStatus.INVALID_REQUEST;
                return(result);
            }
            return(GetGeocodeApiResult(address, resultType));
        }
Exemplo n.º 2
0
        private CoordinateResult GetGeocodeApiResult(string address, ServiceResultTypes resultType)
        {
            var url = googleMapGeocodeApiUrl;

            address = address.Substring(0, address.LastIndexOf('號') + 1);

            if (!string.IsNullOrEmpty(googleMapApiKey))
            {
                url = string.Format("{0}key={1}&address={2}", url, googleMapApiKey, address);
            }
            else if (!string.IsNullOrEmpty(googleMapClientId))
            {
                url = string.Format("{0}client={1}&address={2}", url, googleMapClientId, address);
                var signUrl = Signature.GoogleSignedUrl.Sign(url, googleMapcryptKey);
                return(RequestGeoCode(signUrl, resultType));
            }
            else
            {
                url = string.Format("{0}address={1}", url, address);
            }

            return(RequestGeoCode(url, resultType));
        }
Exemplo n.º 3
0
        private CoordinateResult HandleResponseGeocode(WebResponse response, ServiceResultTypes resultType)
        {
            var result = new CoordinateResult()
            {
                Coordinate = new Coordinate(), Status = ServiceResultStatus.NOT_DEFINED
            };

            StreamReader sr        = new StreamReader(response.GetResponseStream());
            var          apiResult = JsonConvert.DeserializeObject <ApiGeocodeResult>(sr.ReadToEnd());

            result.Status = SetResultStatus(apiResult.status);

            if (result.Status == ServiceResultStatus.OK)
            {
                if (apiResult.results.Count() == 1)
                {
                    var finalResult = apiResult.results.FirstOrDefault();

                    if (finalResult == null)
                    {
                        result.Status = ServiceResultStatus.ZERO_RESULTS;
                        return(result);
                    }

                    if (finalResult.partial_match == false && finalResult.types.Contains(resultType.ToString()))
                    {
                        result.Coordinate.Latitudine  = finalResult.geometry.location.lat;
                        result.Coordinate.Longitudine = finalResult.geometry.location.lng;
                        return(result);
                    }
                }
            }

            result.Status = ServiceResultStatus.ZERO_RESULTS;
            return(result);
        }
Exemplo n.º 4
0
 private CoordinateResult RequestGeoCode(string url, ServiceResultTypes resultType)
 {
     return(HandleResponseGeocode(WebRequest.Create(url).GetResponse(), resultType));
 }
Exemplo n.º 5
0
 public ServiceResult(Unpacker unpacker)
 {
     Result = (ServiceResultTypes)unpacker.UnpackShort();
     unpacker.Unpack(out UserCode);
     unpacker.Unpack(out Message);
 }
Exemplo n.º 6
0
 public ServiceResult(ServiceResultTypes result, long userCode, string message)
 {
     Result   = result;
     UserCode = userCode;
     Message  = message;
 }
Exemplo n.º 7
0
 public ServiceResult(ServiceResultTypes result, long userCode)
 {
     Result   = result;
     UserCode = userCode;
     Message  = null;
 }
Exemplo n.º 8
0
 public ServiceResult(ServiceResultTypes result, string message)
 {
     Result   = result;
     UserCode = 0;
     Message  = message;
 }
Exemplo n.º 9
0
 public ServiceResult(ServiceResultTypes result)
 {
     Result   = result;
     UserCode = 0;
     Message  = null;
 }