SimpleSample-location users-ios

Ask tech team
From QuickBlox Developers (API docs, code samples, SDK)
Jump to: navigation, search

Contents

Sources

Project homepage on GIT — https://github.com/QuickBlox/quickblox-ios-sdk/tree/master/sample-location

Download ZIP - https://github.com/QuickBlox/quickblox-ios-sdk/archive/master.zip


Overview

This sample demonstrates how to work with the QuickBlox Location API.
It allows you to see other users on the Map and share your own position.

It shows you how to:

  1. Retrieve all users' points & add them to the Map
  2. Share your own location



Guide: Getting Started with Location API

Getting a QuickBlox account

http://admin.quickblox.com/register

Creating an application on the Admin panel

http://admin.quickblox.com/apps/new

For further reading there is also this 5 minute guide.

Connecting QuickBlox to your application

To get the information on how to connect to the QuickBlox.framework, please, refer to the IOS-how-to-connect-Quickblox-framework page.

Adding Location features to your application

The Location API provides 2 main features:

  • People - see/show users over map — stores locations and status messages for each user. Connect app users with each other and their environment. Using GPS locations, map integrations and local data, end users can literally 'see' each other on the map and engage with other users.
  • Places — supports POIs (which could be buildings, attractions, events venues, check-in places) or could also be any virtual world object. Places can have profile data along with a photo.

People

Check-in

In order to check-in you must be logged in to act on the user's behalf - please refer to iOS Users API documentation.

Just use this code snippet below if you want to check-in to somewhere:

QBLGeoData *geodata = [QBLGeoData geoData];
 
// place coordinates
geodata.latitude = 23.2344;
geodata.longitude = -12.23523;
geodata.status = @"I'am at QuickBlox house!";
 
[QBRequest createGeoData:currentGeoData
            successBlock:^(QBResponse *response, QBLGeoData *geoData) {
                // Geodata created successfully
            } errorBlock:^(QBResponse *response) {
                // Handle error
            }];

After that other users will be able to see your position.

Check-in with push to near users

You can checkin and notify all users who are near you with push notification:

QBLGeoData *geodata = [QBLGeoData geoData];
geodata.latitude = 23.2344;
geodata.longitude = -12.23523;
geodata.status = @"I'am at QuickBlox house!";
 
[QBLocation createGeoData:geodata andSendPushWithText:@"User Bob is near you" toAllUsersWithinRadius:100 delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Check-in result
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        QBLGeoDataResult *checkinResult = (QBLGeoDataResult *)result;
        NSLog(@"Your checkin: %@", checkinResult.geoData);
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}

After that other users will be able to see your position.

Retrieving checkins

Through filters

There are lots of filters & options that you can use to retrieve checkins. Follow QBLGeoDataGetRequest class documentation, which describes all posible options.

For example, let's retrieve the last 100 checkins, only the last user's checkin, with statuses, sorted by the createdAt field:

[QBRequest geoDataWithFilter:filter page:[QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:70]
                successBlock:^(QBResponse *response, NSArray *objects, QBGeneralResponsePage *page) {
    // Successful response with page information and geodata array
} errorBlock:^(QBResponse *response) {
    // Handle error
}];
Through ID

You can also retrieve particular checkins through their ID:

[QBRequest geoDataWithId:543 successBlock:^(QBResponse *response, QBLGeoData *geoData) {
    // Successful response with geodata
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Updating checkins

If you want to update one of your checkins - just use this code snippet below:

QBLGeoData *geodata = [QBLGeoData geoData];
geodata.ID = 34638;
geodata.latitude = 13.2344;
geodata.longitude = -42.23523;
geodata.status = @"I'am at Pizzzza house!";
 
[QBRequest updateGeoData:geodata successBlock:^(QBResponse *response, QBLGeoData *geoData) {
    // Successful response with page information and geodata array
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Deleting Checkins

There are 2 ways to delete checkins:

  • Deleting a particular checkin by ID
  • Deleting checkins that were created in a period of the last n days
Through ID
[QBRequest deleteGeoDataWithID:11300 successBlock:^(QBResponse *response) {
    // Successful response
} errorBlock:^(QBResponse *response) {
    // Handle error
}];
Mass delete
[QBRequest deleteGeoDataWithID:5 successBlock:^(QBResponse *response) {
    // Successful response
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Places

Creating a Place

There are 2 ways to create a place:


Creating a Place through the Admin panel

Just go to admin.quickblox.com, find the Location module page, then the Places tab and press the Add new place button. The 'add a new place' page will be opened. Pick a location, set a title, description, connect a photo and press the Add button. the new place will be created & shown in the table.

Bulk uploads of places is supported as well.

Creating a Place through the iOS SDK

In order to create a place you must be logged in and to act on a user's behalf - please refer to iOS Users API documentation.

QBLPlace *place = [QBLPlace place];
place.geoDataID = 34691;
place.photoID = 447; // ID of file in Content module
place.title = @"My place title";
place.address = @"London, Gadge st, 34";
place.placeDescription = @"My place description";
 
[QBRequest createPlace:place successBlock:^(QBResponse *response, QBLPlace *place) {
    // Successful response with created place
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Retrieving places

There are 2 ways to retrieve places:

  • Retrieving all places
  • Retrieving a particular place through it's ID
Retrieving all places
[QBRequest placesForPage:[QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:10] successBlock:^(QBResponse *response, NSArray *objects, QBGeneralResponsePage *page) {
    // Successful response with places and page
} errorBlock:^(QBResponse *response) {
    // Handle error
}];
Retrieving a Place through it's ID
[QBRequest placeWithID:71 successBlock:^(QBResponse *response, QBLPlace *place) {
    // Successful response with place
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Updating a Place

If you want to update one of your places - just use the code snippet below:

QBLPlace *place = [QBLPlace place];
place.ID = 1228;
place.placeDescription = @"Cool, Fresh place";
place.title = @"Lime cafe";
 
[QBRequest updatePlace:place successBlock:^(QBResponse *response, QBLPlace *place) {
    // Successful response with place
} errorBlock:^(QBResponse *response) {
    // Handle error
}];

Deleting a Place

[QBRequest deletePlaceWithID:100 successBlock:^(QBResponse *response) {
    //Successful response
} errorBlock:^(QBResponse *response) {
    //Handle error
}];

Comments

Feel free to comment on this page using the form below.

blog comments powered by Disqus