Reputation: 574
I have this map function
function (doc) {
// Leidse plein
// this is now fixed, but needs to be dynamic from the url params
center_latitude = 52.3648111;
center_longitude = 4.8810906;
// this is fixed, but also needs to be dynamic from the url params
radius = 5;
// calc distance between centerpoint and userpoint
distance = Math.acos(
Math.sin(doc.latitude * Math.PI / 180) *
Math.sin(center_latitude * Math.PI / 180)
+
Math.cos(doc.latitude * Math.PI / 180) *
Math.cos(center_latitude * Math.PI / 180) *
Math.cos((doc.longitude - center_longitude) * Math.PI / 180)) * 6371;
// all poi's within 5km radius
if(distance <= radius ) {
emit([doc.title,doc.latitude,doc.longitude], distance);
}
}
So this works, but I need to have it dynamic so I can pass the center_longitude and center_latitude from the url params. I'm still new in CouchDB. Can somebody help me with this?
Upvotes: 1
Views: 315
Reputation: 7938
If you want to use CouchDB for geo-spatial information, one idea is to try out Cloudant Geospatial. It has many features like being able to query according to radius
:
Example of a radius query:
?lat=-11.05987446&lon=12.28339928&radius=100
Example query to find documents that have a geospatial position within a circle:
curl -X GET 'https://education.cloudant.com/crimes/_design/geodd/_geo/geoidx?lat=42.3397&lon=-71.07959&radius=10&relation=contains&format=geojson'
There are detailed descriptions on Cloudant geo documentation.
Upvotes: 0
Reputation: 2121
It is not possible to have parameters in a map function.
I point you to a similar question but it is not applicable in your case.
The list functions or filter functions can receive url parameters but you'll have some performance problems if the number of documents in the database grow as the complete db need to be processed.
Upvotes: 1