title: Google Maps API v3 - PHP - MYSQL
body: <p>GOOGLE MAPS API V3 is what i'm trying to use.</p>
  
  <p>I have all the coordinates in mysql. I just, for example, need to take 5 listings and put them on a map but I'd like to be able to find the center point based on the multiple coordinates I'd like to display, and the zoom level as well. Yeah know?</p>
  
  <p>I'm having the time of my life with something that I know is terribly simple, I just can't figure this API out. I'll paypal $20 to anyone who can help me.</p>
  
  <pre><code>//select * from mysql limit 5
  
  //ok great we got 5 results, great job, format the 5 results so google maps like it, [name,lat,lng] whatever.
  
  //put them on the map and let them be clickable so i can put stuff in the infowindow thing
  
  //make the map adjust to the proper zoom level and center point
  </code></pre>
  
  <h2>UPDATE</h2>
  
  <hr>
  
  <p>This is what i was looking for, hope this helps others.</p>
  
  <p>credit to [Chris B] for the common sense math formula for getting the center coord, the sw cord is the lowest lat and lon, and the ne coord is the greatest lat and lon</p>
  
  <pre><code>sort($lat)&amp;&amp;sort($lon);
  $r['c'] = array_sum($lat)/count($lat).', '.array_sum($lon)/count($lon);
  $r['ne'] = $lat[count($lat)-1].', '.$lon[count($lon)-1];
  $r['sw'] = $lat[0].', '.$lon[0];
  </code></pre>
  
  <hr>
  
  <pre><code>var myOptions = {zoom:4,center: new google.maps.LatLng(&lt;?php echo $r['c']; ?&gt;),mapTypeId:google.maps.MapTypeId.ROADMAP}
  var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
  &lt;?php foreach($x as $l) echo 'new google.maps.Marker({position:new google.maps.LatLng('.$l['lat'].','.$l['lon'].'),map:map,clickable:true});'; ?&gt;
  map.fitBounds(new google.maps.LatLngBounds(new google.maps.LatLng(&lt;?php echo $r['sw']; ?&gt;),new google.maps.LatLng(&lt;?php echo $r['ne']; ?&gt;)));
  </code></pre>