Page 2 of 3

Another geolocation question

Posted: Sun Apr 12, 2015 11:11 pm
by Vince

Bruce,

Thanks for the notes. I'll take another crack at this and see if I can get it working. I probably had the right code a while back, which failed due to the inverted coordinates.

Regards,

Vince


Another geolocation question

Posted: Sun Apr 12, 2015 11:14 pm
by Vince

Just remembered that I swapped the lat lng coordinates multiple times when testing before.


Another geolocation question

Posted: Sun Apr 12, 2015 11:44 pm
by Vince

Bruce,

I swapped the coordinates in the DB as suggested and the query works with fixed coordinates.

Working:

{ "location" : { "$nearSphere" : [-118.1956949,34.758913], "$maxDistanceInMiles" : 10} }

However when I try the coordinates using storage variables the code fails again.

Not working:

{ "location" : { "$nearSphere" : [' + (localStorage.getItem('currentLng') + ',' + (localStorage.getItem('currentLat') + '], "$maxDistanceInMiles" : 25}}

I tried multiple variation of the above without success. Can't find the correct syntax. Also, not sure how I loaded the coordinates in the db reversed.

Regards


Another geolocation question

Posted: Mon Apr 13, 2015 2:32 am
by Bruce Stuart

Hi Vince,

First step is you have the test working. So, let's fix the non working code ... Can you perhaps send an image of how you are executing the code in the service event ? The one that build the where clause ... And then can you also show the error you are getting when you execute the code please ?

I'll watch for your reply for the next few hours ... And get back to you asap.

Best ,
Bruce


Another geolocation question

Posted: Mon Apr 13, 2015 5:35 am
by Bruce Stuart

Vince,

Here's an example of code - using your code - in the builder - of where you would put your source code (click the JS button next to the where clause in your service).

Try the code I created on your behalf. It logs the where clause it builds to the console. If you don't get the right rows - copy the result in the console, switch back to the data service - and paste the where clause in the test window - and click test.

Image

have a good Monday!
bruce


Another geolocation question

Posted: Mon Apr 13, 2015 5:36 am
by Bruce Stuart

oh - and on line 3 there is a mis-spelling it should be :

console.log(sWhereClause );

Bruce


Another geolocation question

Posted: Mon Apr 13, 2015 3:21 pm
by Bruce Stuart

and ... please let me know how - if this works for you..


Another geolocation question

Posted: Mon Apr 13, 2015 6:45 pm
by Vince

Bruce,

I corrected the order that the lat & long were loaded into the db. Then I placed the code you provided in the before send mapping JS button.

Image

This is the response from the console:

{ "location" : { "$nearSphere" : [-118.0957758,34.5900824], "$maxDistanceInMiles" : 10}}

The response correctly filters the results when pasted in the test window, however the results in the app remain unfiltered.

I am missing the item you are mapping from storage to the where clause.

In your example, you have linked "sgolfwhere" to the where clause. I am unclear as to what data you are linking here. I have the user's current lat and long in two separate storage variables. Is "sgolfwhere" a model object or array containing both lat and long?

You also mentioned earlier that I need to run the script you provided in a before send javascript and then the mapping. Later you stated the code was to be inserted in the JS button. So I am a bit confused here. Presently I have the code in the JS button only.

I'm getting close to a solution. Your assistance is greatly appreciated.

Regards,

Vince


Another geolocation question

Posted: Mon Apr 13, 2015 7:13 pm
by Bruce Stuart

Vince,

Sorry for the confusion. Your UI tells the whole story. Please put the code I gave you - that you now have in the field called location - in the 'where' clause - not in the location field (and remove it from the location field)

I believe you can or even should remove location and vendorBarCode from your service as well. Let me know if you decide to keep those fields in your service - why you have them there?

Best,

Bruce


Another geolocation question

Posted: Mon Apr 13, 2015 7:18 pm
by Vince

Bruce,

I went back to double check everything and found I was still using a list service. I thought i had corrected this earlier.

After correcting the error, I am happy to say the app is now filtering the results properly.

My next obstacle is running a query using two where clauses to return results based on two columns.

Many thanks for your assistance.

Regards,

Vince