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!";
 
[QBLocation createGeoData:geodata 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.

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:

QBLGeoDataGetRequest *getRequest = [QBLGeoDataGetRequest request];
getRequest.status = YES;
getRequest.perPage = 100;
getRequest.lastOnly = YES;
getRequest.sortBy = GeoDataSortByKindCreatedAt;
 
[QBLocation geoDataWithRequest:getRequest delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Retrieve checkins result
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        QBLGeoDataPagedResult *checkinsResult = (QBLGeoDataPagedResult *)result;
        NSLog(@"Checkins: %@", checkinsResult.geodata);
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}
Through ID

You can also retrieve particular checkins through their ID:

[QBLocation geoDataWithID:34706 delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Get checkin result
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        QBLGeoDataResult *checkinResult = (QBLGeoDataResult *)result;
        NSLog(@"Checkin: %@", checkinResult.geoData);
    }else{
         NSLog(@"errors=%@", result.errors);
    }
}

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!";
 
[QBLocation updateGeoData:geodata delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Update checkin result
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        QBLGeoDataResult *checkinResult = (QBLGeoDataResult *)result;
        NSLog(@"Checkin: %@", checkinResult.geoData);
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}

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
[QBLocation deleteGeoDataWithID:34640 delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Delete checkin result
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        NSLog(@"Checkin was deleted successfully");
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}
Mass delete
QBLGeoDataDeleteRequest *deleteRequest = [QBLGeoDataDeleteRequest request];
// delete all checkins that were created in period of last 2 days
deleteRequest.days = 2; 
 
[QBLocation deleteGeoDataWithRequest:deleteRequest delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Delete checkins result
    if(result.success && [result isKindOfClass:QBLGeoDataResult.class]){
        NSLog(@"Checkins were deleted successfully");
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}

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";
 
[QBLocation createPlace:place delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Create Place result
    if(result.success && [result isKindOfClass:QBLPlaceResult.class]){
        QBLPlaceResult *placeResult = (QBLPlaceResult *)result;
        NSLog(@"Place: %@", placeResult.place);
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}

Retrieving places

There are 2 ways to retrieve places:

  • Retrieving all places
  • Retrieving a particular place through it's ID
Retrieving all places
PagedRequest *pagedRequest = [PagedRequest request];
pagedRequest.perPage = 20; // 20 places
pagedRequest.page = 1;
 
[QBLocation placesWithPagedRequest:pagedRequest delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Get Places result
    if(result.success && [result isKindOfClass:QBLPlacePagedResult.class]){
        QBLPlacePagedResult *placesResult = (QBLPlacePagedResult *)result;
        NSLog(@"Places: %@", placesResult.places);
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}
Retrieving a Place through it's ID
[QBLocation placeWithID:1190 delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Retrieve Place with ID result
    if(result.success && [result isKindOfClass:QBLPlaceResult.class]){
        QBLPlaceResult *placeResult = (QBLPlaceResult *)result;
        NSLog(@"Place %@", placeResult.place);
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}

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";
 
[QBLocation updatePlace:place delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Update Place result
    if(result.success && [result isKindOfClass:QBLPlaceResult.class]){
        QBLPlaceResult *placeResult = (QBLPlaceResult *)result;
        NSLog(@"Place %@", placeResult.place);
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}

Deleting a Place

[QBLocation deletePlaceWithID:1230 delegate:self];
 
#pragma mark -
#pragma mark QBActionStatusDelegate
 
- (void)completedWithResult:(Result *)result{
    // Delete Place with ID result
    if(result.success && [result isKindOfClass:QBLPlaceResult.class]){
        NSLog(@"Place was deleted successfully");
    }else{
        NSLog(@"errors=%@", result.errors);
    }
}

Comments

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

blog comments powered by Disqus