Skip to content

CodeIgniter Model implementing the haversine formula, giving great-circle distances between two points on a sphere from their longitudes and latitudes.

Notifications You must be signed in to change notification settings

douggrubba/ci_haversine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 

Repository files navigation

CodeIgniter Haversine Model

CodeIgniter Model implementing the haversine formula, giving great-circle distances between two points on a sphere from their longitudes and latitudes.

Installation

Just drop this model into your application/models folder (download or git)

Usage

Load the Model

$this->load->model('haversine');

Define the Table Name

$this->haversine->table_name = 'locations';

Run the "Spatial" query

$locations = $this->haversine->closest(36, -80); //lat, lng

Extra Params

Maximum Distance

$locations = $this->haversine->closest(36, -80, 25); //25 Miles

Maximum Locations

$locations = $this->haversine->closest(36, -80, 25, 10); //10 Locations

Define the Units of Measurement

$locations = $this->haversine->closest(36, -80, 25, 10, 'miles'); //miles or kilometers

Define what fields you would like back

$locations = $this->haversine->closest(36, -80, 25, 10, 'miles', array('id, name')); //false for * or single dim array

TODO

  • More units of measurement (feet, meters)
  • Support joins (ie join company meta to a store locations table)
  • Change direction of result
  • Put units param right after longitude
  • Refractor into a more general GIS model?

NOTES

  • Only tested on MySQL

About

CodeIgniter Model implementing the haversine formula, giving great-circle distances between two points on a sphere from their longitudes and latitudes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages