public GoogleLocationResponse RequestLocations(string text) { var key = text.Trim().ToLowerInvariant(); if (_cacheLocation.ContainsKey(key)) { return(_cacheLocation[key]); } var client = new RestClient("https://maps.googleapis.com"); var request = new RestRequest("maps/api/geocode/json", Method.GET); request.AddParameter("key", _apiKey); request.AddParameter("address", text); var response = client.Execute(request); var data = new GoogleLocationResponse(response.Content); //dynamic data = JsonConvert.DeserializeObject(response.Content); lock (_cacheLocation) { if (!_cacheLocation.ContainsKey(key)) { _cacheLocation.Add(key, data); } } return(data); }
public GoogleLocationResponse RequestLocations(IGeoLatLon point) { var location = GetLocationString(point); var key = location; if (_cacheLocation.ContainsKey(key)) { return(_cacheLocation[key]); } var client = new RestClient("https://maps.googleapis.com"); var request = new RestRequest("maps/api/geocode/json", Method.GET); request.AddParameter("key", _apiKey); request.AddParameter("latlng", location); var response = client.Execute(request); var data = new GoogleLocationResponse(response.Content); //dynamic data = JsonConvert.DeserializeObject(response.Content); lock (_cacheLocation) { if (!_cacheLocation.ContainsKey(key)) { _cacheLocation.Add(key, data); } } return(data); }
public GoogleLocationResponse RequestLocation(string place_id) { var key = place_id; if (_cacheLocation.ContainsKey(key)) { return(_cacheLocation[key]); } var client = new RestClient("https://maps.googleapis.com"); var request = new RestRequest("maps/api/geocode/json", Method.GET); request.AddParameter("key", _apiKey); request.AddParameter("place_id", place_id); var response = client.Execute(request); var data = new GoogleLocationResponse(response.Content); lock (_cacheLocation) { if (!_cacheLocation.ContainsKey(key)) { _cacheLocation.Add(key, data); } } return(data); }