Titanium Appcelerator Quickie: StackMob API Module Part Two

Copy space. New arrows painted on asphalt. Direction future.

Editor’s Note: This post is cross-posted with permission from the Clearly Innovative blog, maintained by Aaron Saunders.


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 login method that was added to the client along with the exposing of the headers property as a parameter to be passed into the client API

Geospatial Queries

To 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 Logout

The module has also been updated with the login method to make is simple to authenticate a user

Logging the current user out

Introduction of Headers Property

Why 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-OrderBy

Get 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 params property to implement the query, and the header to sort the information.

Paging: Range

Using the same headers property, we can ‘page’ through the objects by specifying the range of objects we want returned.


  • Titanium Appcelerator Quickie: StackMob API Module Part One
  • Titanium Appcelerator Quickie: StackMob API Module Part One – A
  • StackMob Website
  • StackMob API Documentation
  • Appcelerator Developer
  • Original Zipped Project Used in the blog posting
  • Download module: stackmob-module.min.js


  1. Aaron I appreciate your articles, but what’s up with the minified module? Does it mean:

    a) You are making the module a commercial product will eventually charge for new versions

    b) You will maintain a closed source license

    c) It will be open/free starting on x date

    I think it’s totally fair for you to choose any of these options, but you should be up front about the licensing intentions.

    Sincerely though good luck with whichever you choose-

    • Lee, the module in minified for two reasons, 1) I simply do not have the resources to support and respond to all of the questions and issue that will pop up if the source code is released at this time. 2) It is very likely that it will be open/free with no support when completed.

Comments are closed.