private List <LatLng> GetPoints(String keyword) { Dictionary <string, LatLng> results = new Dictionary <string, LatLng>(); // Calculate four equidistant points around Sydney to use as search centers // so that four searches can be done. List <LatLng> searchCenters = new List <LatLng>(4); for (int heading = 45; heading < 360; heading += 90) { searchCenters.Add(SphericalUtil.ComputeOffset(SYDNEY, SEARCH_RADIUS / 2, heading)); } for (int j = 0; j < 4; j++) { var result = GetJsonPlaces(keyword, searchCenters[j]).Result; try { for (int i = 0; i < result.Place.Count; i++) { if (!results.ContainsKey(result.Place[i].Id)) { results.Add(result.Place[i].Id, new LatLng(result.Place[i].Geometry.Location.Latitude, result.Place[i].Geometry.Location.Longitude)); } } } catch (Exception) { Toast.MakeText(this, "Cannot process JSON results", ToastLength.Short).Show(); } } return(results.Values.ToList()); }
/** * Makes four radar search requests for the given keyword, then parses the * json output and returns the search results as a collection of LatLng objects. * * @param keyword A string to use as a search term for the radar search * @return Returns the search results from radar search as a collection * of LatLng objects. */ private List <LatLng> getPoints(string keyword) { Dictionary <string, LatLng> results = new Dictionary <string, LatLng>(); // Calculate four equidistant points around Sydney to use as search centers // so that four searches can be done. List <LatLng> searchCenters = new List <LatLng>(4); for (int heading = 45; heading < 360; heading += 90) { searchCenters.Add(SphericalUtil.ComputeOffset(SYDNEY, SEARCH_RADIUS / 2, heading)); } for (int j = 0; j < 4; j++) { string jsonResults = getJsonPlaces(keyword, searchCenters[j]); try { // Create a JSON object hierarchy from the results JSONObject jsonObj = new JSONObject(jsonResults); JSONArray pointsJsonArray = jsonObj.GetJSONArray("results"); // Extract the Place descriptions from the results for (int i = 0; i < pointsJsonArray.Length(); i++) { if (!results.ContainsKey(pointsJsonArray.GetJSONObject(i).GetString("id"))) { JSONObject location = pointsJsonArray.GetJSONObject(i) .GetJSONObject("geometry").GetJSONObject("location"); results.Add(pointsJsonArray.GetJSONObject(i).GetString("id"), new LatLng(location.GetDouble("lat"), location.GetDouble("lng"))); } } } catch (JSONException) { Toast.MakeText(this, "Cannot process JSON results", ToastLength.Short).Show(); } } return(results.Values.ToList()); }