title: How do I search using the Google Maps API?
body: <p>I'm trying to figure out how to search for nearby businesses in an iPhone app using the Google Maps API. I'm completely new to Javascript, and have waded through some of Google's sample code easily enough. </p>
  
  <p>I found how to grab the user's current location. Now I want to search for "restaurants" near that location. I'm just building on the sample code from <a href="http://code.google.com/apis/maps/documentation/v3/basics.html#DetectingUserLocation" rel="nofollow noreferrer">here</a>. I'll post it below with my changes anyway, just in case.</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no" /&gt;
  &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&gt;
  &lt;title&gt;Google Maps JavaScript API v3 Example: Map Geolocation&lt;/title&gt;
  &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
  var currentLocation;
  var detroit = new google.maps.LatLng(42.328784, -83.040877);
  var browserSupportFlag =  new Boolean();
  var map;
  var infowindow = new google.maps.InfoWindow();
  
  function initialize() 
  {
      var myOptions = 
      {
          zoom: 6,
          mapTypeId: google.maps.MapTypeId.ROADMAP
      };
  
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
      map.enableGoogleBar();
  
      // Try W3C Geolocation method (Preferred)
      if(navigator.geolocation) 
      {
          browserSupportFlag = true;
          navigator.geolocation.getCurrentPosition(function(position) 
          {
          // TRP - Save current location in a variable (currentLocation)
          currentLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
          // TRP - Center the map around current location
          map.setCenter(currentLocation);
      }, 
  
          function() 
          {
              handleNoGeolocation(browserSupportFlag);
          });
      }
  
      else 
      {
          // Browser doesn't support Geolocation
          browserSupportFlag = false;
          handleNoGeolocation(browserSupportFlag);
      }
  }
  
  function handleNoGeolocation(errorFlag) 
  {
      if (errorFlag == true) 
      {
          // TRP - Default location is Detroit, MI
          currentLocation = detroit;
          contentString = "Error: The Geolocation service failed.";
      } 
  
      else 
      {
          // TRP - This should never run. It's embedded in a UIWebView, running on iPhone
          contentString = "Error: Your browser doesn't support geolocation.";
      }
  
      // TRP - Set the map to the default location and display the error message
      map.setCenter(currentLocation);
      infowindow.setContent(contentString);
      infowindow.setPosition(currentLocation);
      infowindow.open(map);
  }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body style="margin:0px; padding:0px;" onload="initialize()"&gt;
    &lt;div id="map_canvas" style="width:100%; height:100%"&gt;&lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>