예제 #1
0
        private void processGeolocationQueries(Location loc)
        {
            string unused_value;

            if (locations.TryGetValue(loc.ToString(), out unused_value))
            {
                return;
            }

            String uri = Constants.REVERSE_GEOCODING_URI
                         .Replace(Constants.LAT_PLACEHOLDER, loc.lat + "")
                         .Replace(Constants.LON_PLACEHOLDER, loc.lon + "")
                         .Replace(Constants.KEY_PLACEHOLDER, Constants.OPEN_CAGE_DATA_KEY);

            try
            {
                ReverseGeocodingResponse response = restClient.get <ReverseGeocodingResponse>(uri);
                serviceLocked = false;
                _logger.LogInformation("OpenCageDataService " + response.Rate);
                availableDate             = response.Rate.Reset;
                locations[loc.ToString()] = response.Results[0].Components.State;
            }
            catch (Exception ex)
            {
                _logger.LogInformation("Error requesting external service: " + ex.ToString());
                if (ex.Message.Contains("402"))
                {
                    serviceLocked = true;
                }
            }
        }
 public IActionResult ReverseGeocode(string rvgLat, string rvgLng)
 {
     try {
         ReverseGeocodingRequest  request  = new ReverseGeocodingRequest(rvgLat, rvgLng);
         ReverseGeocodingResponse response = new ReverseGeocodingResponse(request, googleMapsAPIKey);
         bool responseIsOK = response.responseStatus == HttpStatusCode.OK;
         if (responseIsOK)
         {
             ViewBag.Lat = rvgLat;
             ViewBag.Lng = rvgLng;
             return(View(response.Address));
         }
         ViewBag.BadResponseMessage = response.responseStatus;
         return(View());
     } catch (System.Exception) {
         return(View());
     }
 }
예제 #3
0
        public async Task <string> GetAreaName(double latitude, double longitude)
        {
            try
            {
                ReverseGeocodingRequest request = new ReverseGeocodingRequest(Credentials.API_KEY_GOOGLE,
                                                                              latitude,
                                                                              longitude,
                                                                              "administrative_area_level_2");

                ReverseGeocodingResponse response = await _client.ReverseGeocoding(request);

                if (response.status == "OK" && response.results.Count > 0)
                {
                    return(response.results.First().formatted_address);
                }
            }
            catch (System.Exception e)
            {
                _logger?.Log(e.ToString());
            }

            return(string.Empty);
        }