You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Something we originally planned to do but never really needed; I'm putting in this issue to document the kind of complicated mongo query necessary for this.
The zipcodes are saved in the db with a loc param, which is an array like [ <longitude>, <latitude> ]. These can be used with a $near query to get other entities within a radius of the point. Example:
// Mongo shell code, would need to be adapted to use actual mongo node driver// Finds all zipcodes within 20 miles of princetonvarprinceton=db.zipcodes.findOne({zipcode: '08540'});varnearPrinceton=db.zipcodes.find({"loc" : {"$near" : {"$geometry" : {"type" : "Point","coordinates" : princeton.loc},// expected units are meters, so convert miles to meters by multiplying by 1609.34"$maxDistance" : 20*1609.34}}}).toArray();
Unsure how this would be expressed in query params on the API request. Maybe something like GET /api/geo/zipcodes?near=08540&distance=20
If we wanted to get all zipcodes within a radius of several different zipcodes, you should be able to combine this $near operator with the $or operator to construct a proper query.
The text was updated successfully, but these errors were encountered:
Something we originally planned to do but never really needed; I'm putting in this issue to document the kind of complicated mongo query necessary for this.
The zipcodes are saved in the db with a
loc
param, which is an array like[ <longitude>, <latitude> ]
. These can be used with a$near
query to get other entities within a radius of the point. Example:Unsure how this would be expressed in query params on the API request. Maybe something like
GET /api/geo/zipcodes?near=08540&distance=20
If we wanted to get all zipcodes within a radius of several different zipcodes, you should be able to combine this $near operator with the
$or
operator to construct a proper query.The text was updated successfully, but these errors were encountered: