This tutorial is about creating the remote provider of places for the “Around me” tutorial. If you have not read the first part, you must read it first : Around Me tutorial. The RemotePlaceProvider consists in loading the near points from a remote webservice. The first question you may ask is how to set up quickly a backend server with REST/JSON webservices and geoloc features. The answer is Mongolab, a database-as-a-Service (DBaaS) platform. In this tutorial, i will first describe the steps to configure your mongolab database, then i will explain about the client code for Android.
This tutorial is about creating the local provider of places for the “Around me” tutorial. If you have not read the first part, you must read it first : Around Me tutorial. The LocalPlaceProvider consists in loading the near points in the database. Sqlite has no geo feature and this is problematic. I have used the following solution described in this great blog : Query by proximity in Android. To resume, we first start a sql query using a sort and a limit. The result may have small errors so we sort it again in Java using a Comparator and the Android API.
This android tutorial deals about creating an “Around me” screen for your application. “Around me” shows near places around you using your current location. There are different possibilities to retrieve the near points.
The first one is to use Google Places API. You can use it for common places but it may not fit your needs :
- The points are reviewed by Google before being published, and it may takes time. Your places may be refused.
- You can’t add your own categories, so you can’t search using a custom category.
- In the search results, you may have places added by other users. Maybe you want only yours.
The conclusion may be for you : DIY (do it yourself) and this is precisely the goal of this tutorial. I will show you two possible solutions :
- Places stored in the database of your application.
- Places retrieved using a remote service. In this example, i use mongolabs.
Look at the video below to see the result of the tutorial :
Android : AsyncTask – Best pratices that shows you how to code an asynctask with an activity. With a fragment, it is much simplier because you don’t have to manage rotation as the fragment can be set to retainInstance and survive on configuration changes (rotation).