title: Google Places Api sort by distance
body: <p>Currently developing an <code>Android</code> application that returns the closest 20 location to the users current location. </p>
  
  <p><code>Google Places API</code> is returning ~20 places close to the users location but not the <em>closest</em> 20 sorted by distance. </p>
  
  <p>Looking at the <a href="https://developers.google.com/places/documentation/search">Google Places API Documentation</a> does not show anything that I can see to be incorrect. </p>
  
  <p><strong>GetPlaces.java</strong></p>
  
  <pre><code>String types = "accounting|airport|amusement_park|aquarium|art_gallery|atm|bakery|bank|bar|beauty_salon|bicycle_store|book_store|bowling_alley|bus_station|cafe|campground|car_dealer|car_rental|car_repair|car_wash|casino|cemetery|church|city_hall|clothing_store|convenience_store|courthouse|dentist|department_store|doctor|electrician|electronics_store|embassy|establishment|finance|fire_station|florist|food|funeral_home|furniture_store|gas_station|general_contractor|grocery_or_supermarket|gym|hair_care|hardware_store|health|hindu_temple|home_goods_store|hospital|insurance_agency|jewelry_store|laundry|lawyer|library|liquor_store|local_government_office|locksmith|lodging|meal_delivery|meal_takeaway|mosque|movie_rental|movie_theater|moving_company|museum|night_club|painter|park|parking|pet_store|pharmacy|physiotherapist|place_of_worship|plumber|police|post_office|real_estate_agency|restaurant|roofing_contractor|rv_park|school|shoe_store|shopping_mall|spa|stadium|storage|store|subway_station|synagogue|taxi_stand|train_station|travel_agency|university|veterinary_care|zoo";
  resourceURI = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+myLocation.latitude+","+myLocation.longitude+"&amp;radius=500&amp;rankBy=distance&amp;types="+ URLEncoder.encode(types, "UTF-8")+"&amp;sensor=true&amp;key=GOOGLE_MAPS_KEY";
  try {
              String url =resourceURI; //getURL(myLocation.latitude,myLocation.longitude);
  
              HttpParams httpParams = new BasicHttpParams();
              HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
              HttpConnectionParams.setSoTimeout(httpParams, 30000);
              DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);
              HttpGet httpGet = new HttpGet(url);
              httpGet.setHeader("Content-type", "application/json");
              ResponseHandler responseHandler = new BasicResponseHandler();
              String response = (String) httpClient.execute(httpGet, responseHandler);
  
              if (response != null) {
                  mResult = new JSONObject(response);
                  results = mResult.getJSONArray("results");
              }
          }
          catch (ClientProtocolException e) {
              e.printStackTrace();
              return null;
          }
          catch (IOException e) {
              e.printStackTrace();
              return null;
          }
          catch (JSONException e) {
              e.printStackTrace();
              return null;
          }
  
          return results;
      }
  </code></pre>
  
  <p>This returns valid JSON, but not the closest places to the passed in <strong>distance</strong>. I know for a fact that there are closer places than what the request is returning.</p>
  
  <p>For example, I make a request at a known google place, but it is not showing the place I am currently at- but others that are farther. </p>