title: Google Places API photo_reference
body: <p>I have been trying to extract the goolge places api photo reference but have not had any success. I was wondering if someone could help me. Below is my code:</p>
  
  <pre><code>// KEY Strings
  public static String KEY_REFERENCE = "reference"; // id of the place
  public static String KEY_NAME = "name"; // name of the place
  public static String KEY_VICINITY = "vicinity"; // Place area name
  public static String KEY_PHOTO = "photo_reference";
  
  class LoadPlaces extends AsyncTask&lt;String, String, String&gt; {
  
      /**
       * getting google places JSON response
       * */
  
      protected String doInBackground(String... args) {
          // creating Places class object
          googlePlaces = new GooglePlaces();
  
          try {
              String types = MenuActivity.type;
              String keyword = MenuActivity.keyword;
  
               // get nearest places
              nearPlaces = googlePlaces.search(gps.getLatitude(),gps.getLongitude(), 
              types, keyword); 
  
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;
      }
  
      protected void onPostExecute(String file_url) {
          // updating UI from Background Thread
  
          runOnUiThread(new Runnable() {
              public void run() {
                  /**
                   * Updating parsed Places into LISTVIEW
                   * */
  
                  // Get JSON response status
                  String status = nearPlaces.status;
  
                  // Check for OK status
                  if (status.equals("OK")) {
                      // Successfully got places details
                      if (nearPlaces.results != null) {
                          // loop through each place
                          for (Place p : nearPlaces.results) {
                              HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                              map.put(KEY_REFERENCE, p.reference);
                              map.put(KEY_NAME, p.name);
                              map.put(KEY_PHOTO,p.photo);
                              map.put(KEY_VICINITY, p.vicinity);
  
                              // adding HashMap to ArrayList
                              placesListItems.add(map);
  
                          }
                          // list adapter - removed rating
                          ListAdapter adapter = new SimpleAdapter(
                                  MainActivity.this, placesListItems,
                                  R.layout.list_item, new String[] {
                                  KEY_REFERENCE, KEY_NAME, KEY_VICINITY, KEY_PHOTO},
                                  new int[] { R.id.reference, R.id.name, R.id.address, R.id.phptp});
  
                          // Adding data into ListView
                          lv.setAdapter(adapter);
                      }
                  } 
  }
  </code></pre>
  
  <p>Below is my code that performs the search and parses the data:</p>
  
  <pre><code> public class GooglePlaces {
  
  /** Global instance of the HTTP transport. */
  private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
  private static final String LOG_KEY = "GGPlace";
  
  // Google API Key
  private static final String API_KEY = ""; 
  
  // Google Places serach 
  private static final String PLACES_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?&amp;rankby=distance";
  
  private double _latitude;
  private double _longitude;
  private double _radius;
  private String address;
  
  public PlacesList search(double latitude, double longitude, String types, String keyword) 
          throws Exception {
  
      this._latitude = latitude;
      this._longitude = longitude;
  
      try {
  
          HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
          HttpRequest request = httpRequestFactory.buildGetRequest(new GenericUrl(PLACES_SEARCH_URL));
          request.getUrl().put("key", API_KEY);
          request.getUrl().put("location", _latitude + "," + _longitude);
          request.getUrl().put("sensor", "true");
          if(types != null)
          {
              request.getUrl().put("types", types);
              request.getUrl().put("keyword", keyword);
          }
  
          PlacesList list = request.execute().parseAs(PlacesList.class);
          // Check log cat for places response status
          Log.d("Places Status", "" + list.status);
          return list;
  
      } catch (HttpResponseException e) {
          Log.e("Error:", e.getMessage());
          return null;
      }
  
  }
  public static HttpRequestFactory createRequestFactory(
          final HttpTransport transport) {
      return transport.createRequestFactory(new HttpRequestInitializer() {
          public void initialize(HttpRequest request) {
              GoogleHeaders headers = new GoogleHeaders();
              headers.setApplicationName("APP NAME");
              headers.gdataVersion="2";
              request.setHeaders(headers);
              JsonHttpParser parser = new JsonHttpParser(new JacksonFactory());
              request.addParser(parser);
          }
      });
  }
  }
  </code></pre>
  
  <p>This is my PlaceList class:</p>
  
  <pre><code>public class PlacesList implements Serializable {
  @Key
  public String status;
  
  @Key
  public List&lt;Place&gt; results;
  
  }
  </code></pre>
  
  <p>Here is my Place class:</p>
  
  <pre><code> public class Place implements Serializable {
  
  @Key
  public String id;
  
  @Key
  public String name;
  
  @Key
  public String reference;
  
  @Key
  public String vicinity;
  
  @Key
  public Geometry geometry;
  
  @Key
  public List&lt;Photo&gt; photos;
  }
  </code></pre>
  
  <p>And finally my Photo class:</p>
  
  <pre><code>public class Photo implements Serializable {
  
  @Key
  public String photo_reference;
  
  @Key
  public int height;
  
  @Key
  public int width;
  
  }  
  </code></pre>
  
  <p>I guess I am calling or passing the photo_reference the wrong way. I am hoping there is someone out there that can help me out. I've been working on this for weeks and have almost completely given up.</p>