Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Google places Rankby Distance

Hi Cristian,

Yes, this request should find all items within specified radius sorted by nearest.

May be you don't have such items within this radius? Please try to increase radius.

Also please take a look into request to see all response.

Regards.

Cristian Hidalgo
Posts: 0
Joined: Mon Nov 03, 2014 2:38 pm

Google places Rankby Distance

Hi,
The query works fine but when placing the markers it only points out the first return on the map and the rest are missing.
The query returns three answers when testing it , so there should be three markers and not just one.
Is there something im doing wrong with the mapping?

Cristian Hidalgo
Posts: 0
Joined: Mon Nov 03, 2014 2:38 pm

Google places Rankby Distance

var currentlat = parseFloat(localStorage.getItem("current_lat"));
console.log(currentlat);

var currentlong = parseFloat(localStorage.getItem("current_long"));
console.log(currentlong);

var slider_value = parseInt(localStorage.getItem("slider_value"));

console.log(slider_value);

var whereObject = {
"location" : {
"$nearSphere" : [currentlong, currentlat],
"$maxDistanceInKilometers" : slider_value
}
};
console.log("Where object is:");

return JSON.stringify(whereObject);

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Google places Rankby Distance

Hi Cristian,

Anfortunatly you can not add multiple markers on the page with that way(mapping).

Correct way is to use google maps v3 API.

Please pass this tutorial to understand how to add markers on the map:

http://devcenter.appery.io/tutorials/...

Regards.

Ian Usher7109531
Posts: 0
Joined: Tue Sep 16, 2014 6:57 pm

Google places Rankby Distance

Hi Cristian.

Im trying to do something similar with data over here in the UK. I just wondered if you wouldnt mind sharing how you did this, from start to finish. My app would allow the user to get their coordinates and then show them the two nearest items held in a database. My knowledge of javascript is not really good, i understand it, but not entirely. Would you mind sharing how you did this, so that i can replicate it using my own app please?

If not, dont worry ill figure it out at some point.

Thank you,

Ian

Ian Usher7109531
Posts: 0
Joined: Tue Sep 16, 2014 6:57 pm

Google places Rankby Distance

Hello All,

I want to put this in the simplest terms as i've spent so long looking at something that i think is relatively simple, and i don't want to waste anybody else's (or my own time) any longer if necessary.

Using the geolocation service (i.e. my current location) i want to pull back the two nearest items contained within a database.

If i hard code the latitude and longitude (as shown) then i can get the application to return a set of data as expected.

Image

In its simplest terms i want to use the latitude and longitude from the geolocation service in order to determine what is the nearest item.

I have created a local storage variable and i can see from other users that you need to create the code along the lines of:
{ "Geolocation" : { "$nearSphere" : [currentlat, currentlong] } }

What i would like somebody to explain is how it is possible to use the geolocation service, latitude and longitude, and enter that into the query above?

Please please please help me!!! :) Many thanks.

Ian

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Google places Rankby Distance

Hi Ian,

Please try following code in the "where" clause:

precode

var whereObject = { "Geolocation" : { "$nearSphere" : [parseFloat(currentlat), parseFloat(currentlong)] } };

return JSON.stringify(whereObject);

/code/pre

Also don't forget to specify in this code currentlat and currentlong variables.

Regards

Ian Usher7109531
Posts: 0
Joined: Tue Sep 16, 2014 6:57 pm

Google places Rankby Distance

Hi Yurii,

I have finally managed to get this working. I appreciated your assistance (and persistence) with this.

Many thanks,

Ian

Aeneas McBurney
Posts: 0
Joined: Mon Jun 16, 2014 7:49 am

Google places Rankby Distance

HI,

Will the above work in a Collection.query call? I want to return all users within a certain distance from the current user. Currently I'm returning all users and then checking the distance with a distance function. However I think this might timeout when I get too many users.

If I add

var whereObject = { "Geolocation" : { "$nearSphere" : [parseFloat(currentlat), parseFloat(currentlong)] } };

to my query will this work? I would need to pass the current user lon and lat and compare with the lon and lat in the user table.

Thanks,
Aeneas

Return to “Issues”