title: How To Implement the Google Places API
body: <p>Good Evening,</p>
  
  <p>I have been trying to implement a simple Android(tm) application that utilizes Google Places(tm) API to determine local points of interest (such as restaurants and hotels), however I have been having quite a lot of trouble determining how to actually get started.</p>
  
  <p>Resources I have already employed are as follows:</p>
  
  <p>-<a href="https://developers.google.com/maps/documentation/places/" rel="nofollow" title="The Google&#40;tm&#41; Places Documentation">The Google Places(tm) documentation</a></p>
  
  <p>-<a href="http://blog.brianbuikema.com/2010/08/android-development-part-1-using-googles-places-api-to-develop-compelling-location-based-mobile-applications/" rel="nofollow">An Android(tm) development blog hosted by Brain Buikema</a></p>
  
  <p>-The Android(tm) developer documentation on asynchronous tasks</p>
  
  <p>-Various other stackoverflow postings from individuals in similar circumstances</p>
  
  <p>I was simply hoping for some guidance so that anyone in my situation could simply find this post and maybe then be forwarded to some extremely insightful resources.  </p>
  
  <p>Further, I feel that using Google searches to find resources is somewhat inefficient, are there other databases out there that programmers frequently utilize of which I am not aware?  Any recommended literature?</p>
  
  <p>TL;DR...</p>
  
  <p>-I'm looking for some definitive guides for using the Places API, working with JSON objects and networking on the Android(tm) platform.</p>
  
  <p>-I was hoping to be redirected to some useful sources others have found in the past.</p>
  
  <p>-I have included my Main.java file below simply to provide context - I am not looking for answers :)</p>
  
  <hr>
  
  <p>Code for the Main.java class that implements the Places API functionality:</p>
  
  <pre><code>        Button food = (Button) findViewById(R.id.button14);
  
          food.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) 
          {
              type = "restaurant";
  
              //Constructs the urlString
              if(useCurr)
                  urlString = stringConstructor(myKey, lat, lon, radius, sensor, type);
              else
              {
                  //Here, you must update the lat and lon values according to the location input by the user
                  urlString = stringConstructor(myKey, lat, lon, radius, sensor, type);
              }
  
  
  
              //DO HTTPS REQUEST HERE
              urlString = "https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&amp;radius=500&amp;types=food&amp;name=harbour&amp;sensor=false&amp;key=AIzaSyAp24M3GU9V3kWrrezye8CyUrhtpToUhrs";
  
              Results res = new Results();
  
              JSONArray json = res.doInBackground(urlString);
  
              System.out.println(json);
  
          }
      });
  </code></pre>
  
  <p>Code for the Result class that handles the Asynchronous task:</p>
  
  <pre><code>private class Results extends AsyncTask&lt;String, Integer, JSONArray&gt;
  {
      protected JSONArray doInBackground(String...params)
      {
          JSONArray output = null;
  
          try
          {
              try
              {
                  url = new URL(params[0]);   
              }
              catch(MalformedURLException e)
              {
                  System.out.println("URL formed incorrectly! (" + e + ")");
              }
  
              output = (JSONArray) url.getContent();
          }
          catch(Exception e)
          {
              System.out.println("Exception: " + e);
          }
  
          return output;
      }
  }    
  </code></pre>
  
  <p>Currently receiveing an android.os.NetworkOnMainThreatException whenever I click on the "Food" button (described above) in the emulator.</p>
  
  <p>Any advice is greatly welcomed, I am trying to build a really solid foundation on the Android platform.</p>