0 Flares 0 Flares ×Editor’s Note: This post is cross-posted with permission from the Clearly Innovative blog, maintained by Aaron Saunders. AND In Part Two of the Stackmob Appcelerator blog posting, we are going to quickly show how to use the module to make geospatial queries. We will also include the introduction of a
loginmethod that was added to the client along with the exposing of the
headersproperty as a parameter to be passed into the client API
Geospatial QueriesTo keep things simple, I will be updating the objects that were used in part one of this blog post. See this ( Titanium Appcelerator Quickie: StackMob API Module Part One ) You can see in the image below, the new location field that was added to the user object. This location field has a lat lon field that will be used for the geospatial queries. Now lets add some location specific information to your object, set the values for lat lon for searching Here is a gist that has some sample data that was used for this posting This is what the query looks like when searching for data near a location. Notice the calculation into radians, the query requires the distance to be in radians. For example, 10 miles in radians would be 10 / 3963 = 0.0025233409 This is what the query looks like when searching for data within a bounding box. In this example you need to set the bounding box coordinates of the bottom left and top right.
Login and LogoutThe module has also been updated with the
loginmethod to make is simple to authenticate a user Logging the current user out
Introduction of Headers PropertyWhy is this important? Because the headers do all the magic for sorting, paging and querying data. All of the complexities of query formats are not covered in this post, but can be reviewed in the Stackmob Documentation The complete documentation on sorting and paging can be found on the Stackmob API Documentation Page
Sorting: X-StackMob-OrderByGet all User(s) that have a zip code value and sort results by the zip field ascending, search for zip greater that blank field. Notice the use of the
paramsproperty to implement the query, and the header to sort the information.