title: Geolocation Code Not Working for iPhone / iPod Touch / iPad
body: <p>We did some testing at the Apple Store, and we found out our geolocation code (getting latitude and longitude), is not working for iPhone, iPod Touch, or iPad.  I did have to add extra code to get it to work for MacBook / iMac.</p>
  
  <p><strong>Anyone know code to get the latitude / longitude that works for sure on iPod Touch / iPhone / iPad devices?</strong></p>
  
  <p>CODE:</p>
  
  <pre><code>// needed for iPhone / iPad / iTouch
  &lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDrORw0RI-1v-5BixC4T_zLEhcBBwGzyuQ&amp;amp;sensor=true"&gt;&lt;/script&gt;
  
  // needed for iMac / MacBook
  &lt;script src="http://code.google.com/apis/gears/gears_init.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="http://gaychat.me/js/geo.js" type="text/javascript" &gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;&lt;!--
          var ua = navigator.userAgent.toLowerCase();
          var isAndroid = ua.indexOf("android") &gt; -1;
          var isIPhone = ua.indexOf("iphone") &gt; -1;
          var isIPod = ua.indexOf("ipod") &gt; -1;
          var isBlackberry = ua.indexOf("blackberry") &gt; -1;
          var isIPad = ua.indexOf("ipad") &gt; -1;
  
          if (isIPhone || isIPod || isIPad) {
                  function doGeo() {
                          var geolocator = new google.maps.Geocoder();
  
                          geolocator.geocode({},
                                  function(results, status){
                                          var geocoding_url = "geocoding.php?lat=" + results[0].geometry.location.lat() + "&amp;long=" + results[0].geometry.location.lng() + "&amp;email=&lt;?=$brosforbros_email;?&gt;&amp;key=&lt;?=$session_key;?&gt;";
  
                                          $.ajax({
                                                  url: geocoding_url,
                                                  success: function(data) {}
                                          });
                                  }
                          )
  
                          /*function geo_success(position) {
                                  prev_lat = position.coords.latitude;
                                  prev_long = position.coords.longitude;
  
                                  var geocoding_url = "geocoding.php?lat=" + position.coords.latitude + "&amp;long=" + position.coords.longitude + "&amp;email=&lt;?=$brosforbros_email;?&gt;&amp;key=&lt;?=$session_key;?&gt;";
  
                                  $.ajax({
                                          url: geocoding_url,
                                          success: function(data) {}
                                  });
                          }
  
                          function geo_error() {
  
                          }
  
                          if (!!navigator.geolocation) {
                                  wpid = navigator.geolocation.watchPosition(geo_success, geo_error, {enableHighAccuracy:true, maximumAge:30000, timeout:27000}); 
                          }*/
                  }
          } else if (geo_position_js.init()) { // needed for MacBook's / iMac with Safari
                  function doGeo() {
                          geo_position_js.getCurrentPosition(success_callback,error_callback,{enableHighAccuracy:true});
  
                          function success_callback(p) {
                                  geo_lat = p.coords.latitude.toFixed(3);
                                  geo_long = p.coords.longitude.toFixed(3);
  
                                  var url = 'geolocation.php?geo_user_id=&lt;?=$user_id;?&gt;&amp;geo_email=&lt;?=$user_email;?&gt;&amp;geo_lat=' + geo_lat + '&amp;geo_long=' + geo_long;
  
                                  $.ajax({
                                          url: url,
                                          context: document.body,
                                          success: function(data) {
                                          // UPDATE GEOLOCATION
                                          }
                                  });
                          }
  
                          function error_callback(p) {
                                  alert('error='+p.code);
                          }
                  }
          } else {
                  var gl;
  
                  function getCookie(name) {
                          var start = document.cookie.indexOf(name + "=");
                          var len = start + name.length + 1;
  
                          if ((!start) &amp;&amp; (name != document.cookie.substring(0, name.length))) {
                                  return null;
                          }
  
                          if (start == -1) return null;
  
                          var end = document.cookie.indexOf(";", len);
  
                          if (end == -1) end = document.cookie.length;
  
                          return unescape(document.cookie.substring(len, end));
                  }
  
                  function displayPosition(position) {
                          geo_lat = position.coords.latitude;
                          geo_long = position.coords.longitude;
  
                          var url = 'geolocation.php?geo_user_id=&lt;?=$user_id;?&gt;&amp;geo_email=&lt;?=$user_email;?&gt;&amp;geo_lat=' + geo_lat + '&amp;geo_long=' + geo_long;
  
                          $.ajax({
                                  url: url,
                                  context: document.body,
                                  success: function(data) {
                                          // UPDATE GEOLOCATION
                                  }
                          }); 
                  }
  
                  function displayError(positionError) {
                          //alert("error");
                  }
  
                  function doGeo() {
                          try {
                                  if (typeof navigator.geolocation === 'undefined'){
                                  gl = google.gears.factory.create('beta.geolocation');
                                  } else {
                                  gl = navigator.geolocation;
                                  }
                          } catch(e) {}
  
                          if (gl) {
                                  gl.getCurrentPosition(displayPosition, displayError);
                          } else {
                                  //alert("Geolocation services are not supported by your web browser.");
                          }
                  }
          }
  
          doGeo();
      &lt;/script&gt;
  </code></pre>