Re: Best way to store lat/long ??

600 views
Skip to first unread message

Ali

unread,
Mar 9, 2013, 6:44:33 PM3/9/13
to mongod...@googlegroups.com
Actually I have stored them the same way using an array like you have and created a 2d index on the "l" field.

On Thursday, March 7, 2013 6:37:31 PM UTC, Steve Grosz wrote:
Hi, I'm just now starting out with Mongo, so don't be tooooo mean ;)

I am looking at the best way to store lat/long in a record so I can then search for ALL locations within a certain radius........
Currently I have a test system set up and am storing the info as:

> db.parks.find()
{ "_id" : ObjectId("5138ca3b081653470536f87e"), "l" : { "long" : "-116.199281",
"lat" : "43.618353" }, "name" : "Nampa Dog Park", "type" : "Off Leash", "comment
s" : "" }
{ "_id" : ObjectId("5138cc53081653470536f87f"), "l" : { "long" : "-116.233498",
"lat" : "43.604908" }, "name" : "Morris Hill Park", "type" : "Off Leash", "addre
ss" : "10 N. Roosevelt St", "city" : "Boise", "state" : "ID", "zip" : "83705" }
>

Is there a better way to store the coordinates??

Asya Kamsky

unread,
Mar 10, 2013, 6:51:21 PM3/10/13
to mongod...@googlegroups.com
You should definitely never be storing numbers as strings (well, never say never, but if you want to query on them ...)

Note the " " around the coordinates - you won't be able to index them nor query about them as numbers or coordinates if they are stored as strings.

Other than that you might take a look at this page - you will see there are many different formats for storing coordinates which will work (and a few that won't!).


Please do note this warning: "If you use latitude and longitude as your coordinate system, always store longitude first."
Reply all
Reply to author
Forward
0 new messages