Tried hunting for this without much success so help me if you can.
I want to store Geodata specifically a geojson point. What's the best way to go about that?
There is no specific support for geodata in this library, but you can still use the original MongoDb methods to do special stuff.
You just have to save your data in the GeoJSON format (specification here : http://geojson.org/geojson-spec.html). For a simple point, it is just something like that :
$event->location = ['type' => 'Point', 'coordinates' => [100.0, 0.0];
$event->save();
If you want to perform geospatial requests you have to create the index in a migration :
Schema::collection('events', function ($table) {
$table->index(['location' => '2dsphere']);
});
And then you can do :
$query->where('location', 'near', [
'$geometry' => ['type' => 'Point', 'coordinates' => [101.54, 0.43],
'$maxDistance' => 200,
]);
Thanks a bunch guys. Working great.
It takes time to find this information. I think it should be in the documentation ;) Thanks for the info :+1:
But in the migration wich type of data i need to set as column type?
@anodal88 column type ? That doesn't exist in MongoDB !
Most helpful comment
You just have to save your data in the GeoJSON format (specification here : http://geojson.org/geojson-spec.html). For a simple point, it is just something like that :
If you want to perform geospatial requests you have to create the index in a migration :
And then you can do :