Vince
Posts: 0
Joined: Thu Apr 09, 2015 5:00 pm

Another geolocation question

After searching through numerous posts regarding geolocation, and using the tutorials, I still have a question. Using the Google location service works but is too slow, so I am storing both lat and lng in a geopoint column called location. The objective is to search the db (vendors) and place map markers for all records within a give radius from the current lat & lng without using the google service.

Thanks,

Vince

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Another geolocation question

Vince,

Here's a query that I use against my DB in a golf application that I have --- that uses a radius in miles to query a column called geo_latlong - that is of course a DB column that is in geopoint format:

{ "geo_latlong" : { "$nearSphere" : [-111.6342993,33.248663799999996], "$maxDistanceInMiles" : 25}}

Best,

Bruce

Vince
Posts: 0
Joined: Thu Apr 09, 2015 5:00 pm

Another geolocation question

Bruce,

Thanks for the help, but I need to search the db from the current lat & lng in storage rather that a fixed set of coordinates. I am sure there is a way to swap in the storage coordinates but its beyond my skills.

Regards,

Vince

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Another geolocation question

Hi Vincent,

This is the only one approach of searching geopoint in DB.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Another geolocation question

Vincent ,

Here's the code that built the where clause that I scraped from my console log above (Sergiy - I believe Vincent is looking for an actual coding example that does this):

swhere = '{ "geo_latlong" : { "$nearSphere" : [' + slong + ',' + slat + '], "$maxDistanceInMiles" : ' + Appery('slider_radius').val() + '}}';
localStorage.setItem('swhereclause') = swhere;

where slong and slat - in your code can be replaced with memory storage varaibles for example (localStorage.getItem('mylocalStoragelong') for example. and my Appery('slider_radius').val() can be replaced with some local storage variable as well.

You'd place this code in a Javascript event that occurs in your service BEFORE Execution - and then in the designer - mapping event - you'd point the where clause that's being used in your service query - to this local storage variable. Since both the mapping and the Javascript above would be events before execution of the service - please make sure that the Javascript is FIRST and the mapping is second.

Best,
Bruce

Vince
Posts: 0
Joined: Thu Apr 09, 2015 5:00 pm

Another geolocation question

Bruce,

Between the snippets of code you have provided, plus the notes, I believe I can accomplish what i need to do.

Your help is greatly appreciated.

Regards,

Vince

Vince
Posts: 0
Joined: Thu Apr 09, 2015 5:00 pm

Another geolocation question

I have tried dozens of variations of the code provided above to no avail.

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

All attempts to replace the fixed coordinates with storage variables have failed. I have tried too many permutations to list.

I appreciate the help from Bruce, however I still have not found a solution.

The support group at Appery has yet to provide any viable assistance. Have I not posed the question properly? I spent a significant amount of time researching this issue before posting. There are hundreds of geolocation questions, and I've read most of them without success.

There is ample documentation, such as;

{
"location" : {
"$nearSphere" : [48.208, 16.373],
"$maxDistanceInKilometers" : 550
}
}

However, there are no viable samples that provide the proper syntax using storage variables in place of the fixed coordinates. I've spent hours working on this but cant find the correct syntax.

I have also taken code directly from the documentation...

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

and tested it in the list service. I get either all records, regardless of distance, or an error.

One observation, the "location" geopoint column in my DB lists latitude, longitude. The code above has that reversed.

The gepoint column in my db is named "location" . The storage variables are "currentLat" and currentLng.

I am quite certain the solution is simple and I am just missing something. I'd appreciate some assistance from the appery staff or anyone else.

Vince
Posts: 0
Joined: Thu Apr 09, 2015 5:00 pm

Another geolocation question

I appreciate all assistance, however did you read my question? Your response provides no useful information of any kind.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Another geolocation question

Vince,

A quick observation for you.

  1. The database column needs to be of geopoint type. I'm sure this is so, just making sure .

  2. The database type of geopoint 'requires' that in order to do any searching... That you load the data as long, lat. if you load it the other way around ... You will get errors or unpredictable results, if in doubt .... Please look at, by doing a Google search ... Mongodb documentation for data of geopoint type.

  3. Yes, it's backwards from Google data ... Which is lat, long. Please take that as a given.

    I would start by correcting the data in your collection to be long, lat... And retest your service . Then let us know what you get back.

    Best, Bruce

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Another geolocation question

Finally ... In reading your post .... Please make sure that you are doing your testing in a query service ( again, I'm sure you are ... But the words you say 'list service' ...and that you are putting the query above... The test one.... Into the where clause parameters ) cccc

Return to “Issues”