Page 1 of 1

Geospatial Query

Posted: Tue Mar 03, 2015 2:59 pm
by Nathan Anyonge

We have implemented a search query to display database content 40 metres from users location based on this java script:

params.criteria = {
"location" : {
"$nearSphere" : [48.208, 16.373],
"$maxDistanceInMiles" : 80
}
};

We would like the query to pull content based on the users current location, we store the users current location in a storage variables " userLng" and "userLat".
This is what what we changed it to:

params.criteria = {
"location" : {
"$nearSphere" : [localStorage.getItem("userLat"), localStorage.getItem("userLng")],
"$maxDistanceInKilometers" : 0.4
}
};

However its is still not working, any advice as to the proper script to pull information from the storage variables "userLat" and "userLng" would be much appreciated?


Geospatial Query

Posted: Wed Mar 04, 2015 5:53 am
by Yurii Orishchuk

Hi Nathan,

You need to:

  1. add to your service (which is server script) some request parameters. Like "lat" and "lng". (client side)

  2. pass your storage values to these "lat" and "lng" service request parameters. (client side)

  3. then you can get these values in server code (server code side).

    Regards.


Geospatial Query

Posted: Sun May 24, 2015 8:00 pm
by Asmaa AlHammadi

can you please specify the steps? cause I really need to understand it

thank you,


Geospatial Query

Posted: Mon May 25, 2015 1:22 pm
by Asmaa AlHammadi

like what is the service code that need to be used


Geospatial Query

Posted: Fri May 29, 2015 12:46 am
by Yurii Orishchuk

Hi Asmaa,

Here is a JS code for server code that shows you how to work with geoSpatial requests:

precode

var dbId = "52fd3d0xxxxxx11c89917&quot // commented out
//You should use here your collection name.
var collectionName = "dogs&quot

var params = {};

params.criteria = {
"location": {
"$nearSphere": [48,40],
"$maxDistanceInMiles": 80
}
};

query = Collection.query(dbId, collectionName, params);

response.success(query, "application/json");

/code/pre

Regards.