Пример #1
0
        public GeoCodeResponse ParseResultsJson(string addressesJson, string address)
        {
            _addressObject   = JObject.Parse(addressesJson);
            _geoCodeResponse = null;
            try
            {
                _geoCodeResponse = JsonConvert.DeserializeObject <GeoCodeResponse>(addressesJson);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            if (_geoCodeResponse == null || _geoCodeResponse.status == null)
            {
                return(_geoCodeResponse);
            }

            switch (_geoCodeResponse.status.ToUpper())
            {
            case "OK":
            case "ZERO_RESULTS":
            case "REQUEST_DENIED":
            case "INVALID_REQUEST":
            {
                if (_cacheResults)
                {
                    _addresses.Add(address, _geoCodeResponse);
                }
                break;
            }

            case "OVER_QUERY_LIMIT":
            {
                _dateWentOverLimit     = System.DateTime.Now.Date;
                _googleMapApiOverLimit = true;
                break;
            }

            case "UNKNOWN_ERROR":
            {
                //if (!string.IsNullOrWhiteSpace(_googleGeoApiKey))
                //{
                //    _addressesJson = await GetGoogleMapEncode(address);
                //    _addressObject = JObject.Parse(_addressesJson);
                //    _geoCodeResponse = JsonConvert.DeserializeObject<GeoCodeResponse>(_addressesJson);
                //    if (_geoCodeResponse.status == "OVER_QUERY_LIMIT")
                //    {
                //        _dateWentOverLimit = System.DateTime.Now.Date;
                //        _googleMapApiOverLimit = true;
                //    }
                //    else if (_cacheResults)
                //        _addresses.Add(address, _geoCodeResponse);
                //}

                break;
            }
            }

            return(_geoCodeResponse);
        }
Пример #2
0
        public async Task <GeoCodeResponse> ReverseLookupAsync(string address)
        {
            if (_cacheResults)
            {
                if (_addresses.ContainsKey(address))
                {
                    _geoCodeResponse = _addresses[address];
                    return(_addresses[address]);
                }
            }

            _addressesJson = await GetGoogleMapEncode(address);

            return(await this.ParseResultsJsonAsync(_addressesJson, address));

            //_addressObject = JObject.Parse(_addressesJson);
            //_geoCodeResponse = JsonConvert.DeserializeObject<GeoCodeResponse>(_addressesJson);
            //switch (_geoCodeResponse.status.ToUpper())
            //{
            //    case "OK":
            //    case "ZERO_RESULTS":
            //    case "REQUEST_DENIED":
            //    case "INVALID_REQUEST":
            //        {
            //            if (_cacheResults)
            //                _addresses.Add(address, _geoCodeResponse);
            //            break;
            //        }

            //    case "OVER_QUERY_LIMIT":
            //        {
            //            _dateWentOverLimit = System.DateTime.Now.Date;
            //            _googleMapApiOverLimit = true;
            //            break;
            //        }

            //    case "UNKNOWN_ERROR":
            //        {
            //            _addressesJson = await GetGoogleMapEncode(address);
            //            _addressObject = JObject.Parse(_addressesJson);
            //            _geoCodeResponse = JsonConvert.DeserializeObject<GeoCodeResponse>(_addressesJson);
            //            if (_geoCodeResponse.status == "OVER_QUERY_LIMIT")
            //            {
            //                _dateWentOverLimit = System.DateTime.Now.Date;
            //                _googleMapApiOverLimit = true;
            //            }
            //            else if (_cacheResults)
            //                _addresses.Add(address, _geoCodeResponse);
            //            break;
            //        }
            //}

            //return _geoCodeResponse;
        }