Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 32: Saving a geopoint with API
February 8, 2015 by markpiller
Spread the love

In my previous posts I described how to set up a sample Geolocation data set and how to retrieve geopoints using the API. The geopoints in your application would not be the ones from the sample data set, we used it only to make it easier to get started with Backendless Geo location. Adding geopoints to your Backendless backend can be done either with the API or by using data import. In this post I will review the first approach – saving geopoints with API.

From my introduction to geolocation you might know that a geopoint consists of the following:

  • A pair of GPS coordinates: latitude and longitude.
  • A category the geopoint belongs to.
  • Optional metadata which is a collection of arbitrary name/value pairs.

The sample code below saves two geopoints in your Backendless backend. One point which represents Dallas, TX on the map, is added using the synchronous API. The other one represents Houston, TX and it is added with the asynchronous API call. Notice that both geopoints are added to the “cities” category, which will be created dynamically on the server if it does not exist. There are also some metadata such as the city name, population size and a URL of an image of the city skyline:

Asynchronous call (Plain Java and Android):

Synchronous call (Plain Java only):

Asynchronous API sample:

Synchronous API sample:

Asynchronous sample 

Synchronous sample

Asynchronous sample 

Synchronous sample

After you run the code above, you can verify that the geo points are added to the backend using Backendless console:

  1. Login to the Backendless developer console, select the app and click the Geolocation icon.
  2. Click the cities category, the console should show the points as in the screenshot below:
    adding geo points to backendless - Feature 32: Saving a geopoint with API

Enjoy!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+