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)); }
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)); }
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); }
private CoordinateResult RequestGeoCode(string url, ServiceResultTypes resultType) { return(HandleResponseGeocode(WebRequest.Create(url).GetResponse(), resultType)); }
public ServiceResult(Unpacker unpacker) { Result = (ServiceResultTypes)unpacker.UnpackShort(); unpacker.Unpack(out UserCode); unpacker.Unpack(out Message); }
public ServiceResult(ServiceResultTypes result, long userCode, string message) { Result = result; UserCode = userCode; Message = message; }
public ServiceResult(ServiceResultTypes result, long userCode) { Result = result; UserCode = userCode; Message = null; }
public ServiceResult(ServiceResultTypes result, string message) { Result = result; UserCode = 0; Message = message; }
public ServiceResult(ServiceResultTypes result) { Result = result; UserCode = 0; Message = null; }