How to create Chat and other services using Location API
Contents |
How it works
QuickBlox Location provides wide functionality which can be used for creating, retrieving and removing the data as well as sorting and requesting the data in required format. Here we will work with a universal field named Status which allows you to store custom string data. It allows building many features and the only thing to remember is that you should consider the limit of 1000 symbols.
Normally when dealing with API you will use text data. There are cases however where you might want to transfer more complex data structures (such as HTML code or text data arrays) or a binary code. We cannot use HTML/XML markup as the client and server are exchanging text messages that are wrapped into XML or JSON - wrapping any kind of markup might cause issues with validation or data loss. The solution for this is to exchange data using the base64 encoding.
Wrapping Chat or other data in base64
Given below is a tested way of using our GeoLocation Service and GeoData as a "transport" for custom data, in this case a public/private chat.
The way to create additional service:
1. Download SDK for your platform (find links in the left sidebar). SDK allows you to work with GeoData object. We use GeoData because its Status field (string) is not strictly validated. QuickBlox users REST which means that requests are sent using form fields and server responses come in XML.
2. Define data structure which you need for your custom functionality.
Example: wrapping chat messages
Structure is a message. It can be specified with type and parameters. To do this we enter the field <t>, that is indicates type of a message (1 – location, 2 – public chat, 3 – private chat).
<m>
<t> Message type (INT) (1- location, 2 - chat etс.)</t>
<to> Destination (for private chat)</to>
<from> Author (for both types of chat)</from>
<text> Message text </text>
</m>
3. In your project - add means for creating and encoding the messages:
- Create a message (following the scheme above)
- Encode message into base64
- Create GeoData object
- Add your base64 message to GeoData Status field
- Send it to the server
4. In your project - add means for receiving messages. General principle – take all GeoData objects, extract messages, decode them, sort and choose the ones which are needed (for example by type or recipient).
Recommendations on how to process data
Considerable resources and time are required to process the data using the given approach. Things can be improved either by using а background mode of GeoData loading that is provided in SDK (only in Windows Mobile version right now) or ping the server periodically, collect the data, cache it and use only last data pages.
Samples
Our 'SuperSamples' are currently using this method to power the Map+Chat feature so it might be much easier for you to download an existing working project for your platform, add your application key/secret to match your QuickBlox app account and start building your project from there. Here are the links to MapChat code samples for all major platforms: iOS, Android, Windows Phone, Web/Facebook
And here are screenshots of apps which are already using this method to power their Map+Chat feature:



