25. HAVING ADDED SEVERAL PLACES
// Assuming collection is defined
// We can now add the GeoSpatial Index
$collection->ensureIndex(array("loc"=>"2d");
// Defining my current location
$my_location = array(101.67646, 3.127896);
// Find Nearest Locations
$nearest_place = $collection->command(array(
"geoNear" => "loc",
"near" => $my_location,
"spherical" => true,
"num" => 1)
)
// Ready for AJAX listeners
echo json_encode($nearest_place);
26. KL MongoDB User-Group
THE END RESULTS
( if connected to something such as gSpot – for example )
27. LEARN MORE
BOLLOCKS
( about mongoDB and the products, services and people using it )
Kuala Lumpur MongoDB User Group
https://www.facebook.com/groups/klmug/
1st Wednesday of Every Month
Tweet Me - @m_smalley