title: How do I make a query to Google Places API?
body: <p>I'm trying to make a client-side jquery request on an HTML page (in my Spring project) to the Google Places API so I can determine the ratings of a particular business type within a radius of x,y. At the moment I'm trying to do it like so: </p>
  
  <pre><code>  function getCafe(){
  
         $(document).ready(function(){
             $('.search_latitude').val(marker.getPosition().lat());
             $('.search_longitude').val(marker.getPosition().lng());
  
             // These are lat long values calculated by the user's searched location on a google map on the client side
             var Lat = marker.getPosition().lat();
             console.log(Lat);
             var Long = marker.getPosition().lng();
             console.log(Long);
             var cafeRatings = [];
             // Ive disclosed my API Key
             var url = "https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=" + Lat + "," + Long + "&amp;amp;radius=500&amp;amp;type=restaurant&amp;amp;keyword=cruise&amp;amp;key=MY_API_KEY";
  
             $.ajax({
              type: "GET",
              dataType: "xml",
              url: url,
              success: function(xml) {
                  $(xml).find('results').each(function(){
                      $(this).find("rating").each(function(){
                          var rating = $(this).text();
                          cafeRatings.push(rating);
                      });
                  });
                 //This is a simple debug to display the contents of the rating array to ensure the parse worked correctly
                  alert(cafeRatings.join("\n"));
              }
             });
            });
  
      } 
  </code></pre>
  
  <p>However Michael Geary's answer to this question <a href="https://stackoverflow.com/questions/15847623/googles-places-api-and-jquery-request-origin-http-localhost-is-not-allowed">Google&#39;s Places API and JQuery request - Origin http://localhost is not allowed by Access-Control-Allow-Origin</a> has lead me to believe I cannot use an Ajax jquery to access the API this way and I have to "use the Places Library from the Maps API V3. (As I) can't just hit a URL directly from JavaScript or jQuery code."</p>
  
  <p>With that being said I've found the documentation to do this to be quite broad and resources online seem to be quite limited. Has anyone any experience on how to simply get the rating elements from the API stored into an array in JS so I can calculate the average and display it in a text box?</p>
  
  <p>In case it's needed this how the XML formatted API looks</p>
  
  <pre><code>&lt;PlaceSearchResponse&gt;
  &lt;status&gt;OK&lt;/status&gt;
  
  
   &lt;result&gt;
           &lt;name&gt;Sydney Showboats&lt;/name&gt;
           &lt;vicinity&gt;32 The Promenade, Sydney&lt;/vicinity&gt;
           &lt;type&gt;travel_agency&lt;/type&gt;
           &lt;type&gt;restaurant&lt;/type&gt;
           &lt;type&gt;food&lt;/type&gt;
           &lt;type&gt;point_of_interest&lt;/type&gt;
           &lt;type&gt;establishment&lt;/type&gt;
      &lt;geometry&gt;
          &lt;location&gt;
          &lt;lat&gt;-33.8675570&lt;/lat&gt;
          &lt;lng&gt;151.2015270&lt;/lng&gt;
          &lt;/location&gt;
            &lt;viewport&gt;
             &lt;southwest&gt;
               &lt;lat&gt;-33.8689120&lt;/lat&gt;
               &lt;lng&gt;151.2001126&lt;/lng&gt;
             &lt;/southwest&gt;
             &lt;northeast&gt;
               &lt;lat&gt;-33.8662141&lt;/lat&gt;
               &lt;lng&gt;151.2028105&lt;/lng&gt;
             &lt;/northeast&gt;
            &lt;/viewport&gt;
      &lt;/geometry&gt;
      &lt;rating&gt;3.8&lt;/rating&gt; &lt;------ This is the element im trying to ad to the array
      &lt;icon&gt;
      https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png
      &lt;/icon&gt;
      &lt;reference&gt;
      CmRSAAAALItuCtuLapozzsjq3dmKqj7NDik149XsgUwHD3ob5AWfHYlZtykuJbQa0cq0GMqX8dRgucTCmitnXgV-ekE3GfV7910rzHhx3ZuadVYNuWMzLDVZDCj2G1yiBw8r_hhgEhCPDXsniaZ2ZrkvYyXFfmQrGhSzdmkAEz4stXNx2qFe-GqAlldzgw
      &lt;/reference&gt;
      &lt;id&gt;ce4ffe228ab7ad49bb050defe68b3d28cc879c4a&lt;/id&gt;
      &lt;opening_hours&gt;
      &lt;open_now&gt;false&lt;/open_now&gt;
      &lt;/opening_hours&gt;
      &lt;photo&gt;
      &lt;photo_reference&gt;
      CmRaAAAAh4dP9hsZ_6515QNxouVnuYFYKemmf8BE01rcaOvkFlILQiwGNe_OAX0ikmobMmWZJvyjsFEsn7j1TFhauHSrek8nY5GsW24_6nwJsqEwHTUC10SL5gQITHhkdam50G1PEhCP-C7Of2mkjqJCTYFeYGWuGhQjVoWASHiGSp3WHm26Bh2sYOglZw
      &lt;/photo_reference&gt;
      &lt;width&gt;2048&lt;/width&gt;
      &lt;height&gt;1152&lt;/height&gt;
      &lt;html_attribution&gt;
      &lt;a href="https://maps.google.com/maps/contrib/107415973755376511005/photos"&gt;Sydney Showboats&lt;/a&gt;
      &lt;/html_attribution&gt;
      &lt;/photo&gt;
      &lt;place_id&gt;ChIJjRuIiTiuEmsRCHhYnrWiSok&lt;/place_id&gt;
      &lt;scope&gt;GOOGLE&lt;/scope&gt;
      &lt;/result&gt;
  ........
  &lt;/PlaceSearchResponse&gt;
  </code></pre>