title: What is the Best MySQL Database Formatting Type for GPS Coordinates?
body: <p>I have a script which is inserting latitude and longitude into the MySQL database.  I have assigned these rows as: </p>
  
  <pre><code>`gpslat` DECIMAL(11,4)  NOT NULL ,
  `gpslong` DECIMAL(11,4)  NOT NULL ,
  </code></pre>
  
  <p>For some reason, when I pass the string <code>gpslat=45.7834</code> and <code>gpslong=78.7834</code> I am getting a value in the database without the full string as <code>gpslat=45.0000</code> and <code>gpslong=78.0000</code></p>
  
  <p>Any ideas why this is not just sending the complete values?</p>
  
  <hr>
  
  <p>PHP Addition:</p>
  
  <pre><code>function upload($lat, $long) {
  
  if (gpsData['error']==0) {
      $result = query("INSERT INTO gpsTable(gpslat,gpslong) VALUES('%d','%d')",$lat,$long);
  }
  </code></pre>
  
  <p>I have the <code>$lat</code> and <code>$long</code> values being passed in this case as <code>$lat=45.7834</code> and <code>$long=78.7834</code></p>
  
  <p>Query Function:</p>
  
  <pre><code>function query() {
  global $link;
  $debug = false;
  
  //get the sql query
  $args = func_get_args();
  $sql = array_shift($args);
  
  //secure the input
  for ($i=0;$i&lt;count($args);$i++) {
      $args[$i] = urldecode($args[$i]);
      $args[$i] = mysqli_real_escape_string($link, $args[$i]);
  }
  
  //build the final query
  $sql = vsprintf($sql, $args);
  
  if ($debug) print $sql;
  
  //execute and fetch the results
  $result = mysqli_query($link, $sql);
  if (mysqli_errno($link)==0 &amp;&amp; $result) {
  
      $rows = array();
  
      if ($result!==true)
      while ($d = mysqli_fetch_assoc($result)) {
          array_push($rows,$d);
      }
  
      //return json
      return array('result'=&gt;$rows);
  
  } else {
  
      //error
      return array('error'=&gt;'Database error');
  }
  }
  </code></pre>