Start a new topic
Answered

Using BETWEEN & AND in the query parameter

Hello,


My question is how to use BETWEEN & AND on the query parameters.


I have a collection called "cities" like in the image below has latitude and longitude fields.




 

image



What I want to do is hitting API URL something like this below



https://baas.kinvey.com/appdata/XXXXXX/WorldCities?query={"latitude ":"31.77998, 35.77998 "} && {"longitude ":"33.77998, 38.77998 "} 


--- I will send two latitudes and two longitudes.


What expected is:


Bring the Intersection between (all the cities that fall between these two latitudes) && (all the cities that fall between these two longitudes)






Best Answer

Hello Mohamed,


Please take a look at $within operator in Kinvey Location queries guide on this link. When using $box, the coordinates represent the lower-left and upper-right corners of the box. Following is the example from Kinvey guides:

?query={"_geoloc":{"$within":{"$box":[[-70,44],[-72,42]]}}}



Thanks,

Pranav

Kinvey


Answer

Hello Mohamed,


Please take a look at $within operator in Kinvey Location queries guide on this link. When using $box, the coordinates represent the lower-left and upper-right corners of the box. Following is the example from Kinvey guides:

?query={"_geoloc":{"$within":{"$box":[[-70,44],[-72,42]]}}}



Thanks,

Pranav

Kinvey

Thanks, Pranav, I got it. But now in my collection, I have two separated fields as latitude and longitude.

Is there any way to create a new field called "_geoloc" with combined [long,lat]?


Thanks,

Mohamed

Hello Mohamed,


On Kinvey console -> "cities" collection, click on "+ Add Column" button and add a new column named "_geoloc". Values in this column must be in "[longitude, latitude]" format. 


Thanks,

Pranav

Kinvey

Hello Pranav,


Thaks for your reply.

Yes, I know what you mean, but I mean that I have already data on my fields "Long and Lat", what I want to do is creating a field called "_geoloc" and automatically filled by data collected from "long and late" with the format "'[long,lat]". I want to make it automatically.


Thanks

Mohamed,


Since you were able to move past this issue using 'Export Data' and 'Import Data' features of data collections, I am marking this forum post as answered.


Thanks,

Pranav

Kinvey

Login or Signup to post a comment