Skip to content

Instantly share code, notes, and snippets.

@emulsion-io
Created August 19, 2013 15:05
Show Gist options
  • Save emulsion-io/6270168 to your computer and use it in GitHub Desktop.
Save emulsion-io/6270168 to your computer and use it in GitHub Desktop.
Géolocalisation : Calcule de distance lat/long avec Codeigniter
<?php
$this->db->select("*, ( 6371 * acos( cos( radians('".$geoc['lat']."') ) * cos( radians( geoc_adresse.lat ) ) * cos( radians( geoc_adresse.long ) - radians('".$geoc['long']."') ) + sin( radians('".$geoc['lat']."') ) * sin( radians( geoc_adresse.lat ) ) ) ) AS distance");
$this->db->join('geoc_adresse', 'geoc_adresse.id_geoc = agenda.geoc_adresse_id_geoc');
$this->db->having("distance < '".$geoc['km']."'");
$this->db->order_by('distance');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment