Пример #1
0
  public ArrayList<Place> findPlaces(
      double latitude, double longitude, String placeType, double radius) {

    String urlString = makeUrl(latitude, longitude, placeType, radius);

    try {
      String json = getJSON(urlString);

      Log.d("JSON String", "" + json);
      JSONObject object = new JSONObject(json);
      JSONArray array = object.getJSONArray("results");

      ArrayList<Place> arrayList = new ArrayList<Place>();
      for (int i = 0; i < array.length(); i++) {
        try {
          Place place = Place.jsonToPlaceSearch((JSONObject) array.get(i));
          Log.v("Google Places ", "" + place);
          arrayList.add(place);
        } catch (Exception e) {
        }
      }
      return arrayList;
    } catch (JSONException ex) {
      Log.d("PlaceSearchException", "" + ex.getMessage());
    }
    return new ArrayList<Place>();
  }
Пример #2
0
  public Place getPlaceDetails(String placeId) {

    String urlString = makeUrl(placeId);
    try {
      String json = getJSON(urlString);
      JSONObject object = new JSONObject(json);

      JSONObject placeDetails = object.getJSONObject("result");

      Place place = Place.jsonToPlaceDetails(placeDetails);
      Log.d("Place Details", "" + json);
      return place;

    } catch (Exception ex) {
      Log.d("PlaceDetailException", "" + ex.getMessage());
    }
    return new Place();
  }