Skip to content

Instantly share code, notes, and snippets.

@kovagoz
Created January 10, 2014 14:55
Show Gist options
  • Save kovagoz/8355716 to your computer and use it in GitHub Desktop.
Save kovagoz/8355716 to your computer and use it in GitHub Desktop.
Doctrine geospatial query with GeoJson
<?php
use GeoJson\Geometry\Point;
$city = new City;
$city->name = 'Budapest';
$city->coordinates = new Coordinates(47.51, 19.03);
$city->save();
$city = DB::createQueryBuilder('City')
->field('coordinates')->geoNear(new Point([47.52, 19.12]))
->limit(1)
->getQuery()
->getSingleResult();
echo $city->name;
var_dump($city->distance); // in meters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment