Skip to content

Storing Geodata #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
r115 opened this issue Nov 28, 2014 · 6 comments
Closed

Storing Geodata #371

r115 opened this issue Nov 28, 2014 · 6 comments

Comments

@r115
Copy link

r115 commented Nov 28, 2014

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?

@jenssegers
Copy link
Contributor

There is no specific support for geodata in this library, but you can still use the original MongoDb methods to do special stuff.

@alexandre-butynski
Copy link
Contributor

alexandre-butynski commented Nov 30, 2014

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,
]);

@r115
Copy link
Author

r115 commented Dec 4, 2014

Thanks a bunch guys. Working great.

@r115 r115 closed this as completed Dec 4, 2014
@ByScripts
Copy link

It takes time to find this information. I think it should be in the documentation ;) Thanks for the info 👍

@anodal88
Copy link

But in the migration wich type of data i need to set as column type?

@alexandre-butynski
Copy link
Contributor

@anodal88 column type ? That doesn't exist in MongoDB !

benargo added a commit to benargo/laravel-mongodb that referenced this issue Jun 4, 2017
Since mongodb#371 was raised back in 2014 I’ve wanted a way to improve and simplify adding geospatial indexes.
benargo added a commit to benargo/laravel-mongodb that referenced this issue Jun 4, 2017
Since mongodb#371 was raised back in 2014 I’ve wanted a way to improve and simplify adding geospatial indexes.
benargo added a commit to benargo/laravel-mongodb that referenced this issue Jun 4, 2017
Since mongodb#371 was raised back in 2014 I’ve wanted a way to improve and simplify adding geospatial indexes.
benargo added a commit to benargo/laravel-mongodb that referenced this issue Jun 4, 2017
Since mongodb#371 was raised back in 2014 I’ve wanted a way to improve and simplify adding geospatial indexes.
mnphpexpert added a commit to mnphpexpert/laravel-mongodb that referenced this issue Sep 2, 2024
Since mongodb#371 was raised back in 2014 I’ve wanted a way to improve and simplify adding geospatial indexes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants