Goindoor iOS SDK
介绍
Goindoor框架负责与服务器通信,并为开发者提供轻松访问数据的权限,同时还提供了一些额外功能,例如位置提供程序、路由、统计和资产管理。详细开发者文档可以在此处找到。
准备环境
该项目应使用iOS7作为基础SDK版本。同时,还需要在构建设置的链接部分添加–ObjC
标志。
需要路由包以提供基本图标和字符串以进行路由。
本框架可以与大多数可用的地图API一起使用。可以使用Google Maps通过使用OYMFloor(GoogleMaps)
类别。在这种情况下,需要添加所有Google Maps for iOS框架+info。
从版本2.4.0开始,此SDK还需要ZipZap框架和libz和libc++库进行编译。
CocoaPods
Goindoor 框架同样可以通过 CocoaPods 获得。您可以通过向 Podfile
中添加以下行将框架添加到现有项目中:
pod 'GoIndoor'
准备示例应用
为了使用室内框架,需要创建一个基本 iOS 应用。在完成上一节中提到的所有修改后,请记住应用程序正在使用蓝牙和 WiFi/网络连接;因此,需要检查所有这些功能是否可用。下一步是定义一个符合 OYMLocationDelegate
协议的委托类。此委托将在每次计算位置时被调用。它还提供有关位置提供程序是否已正确启动的信息。
/**
* This delegate will provide feedback to the user regarding the indoor location library.
*/
@protocol OYMLocationDelegate <NSObject>
@required
/**
* This method is called when the indoor location service has been
* correctly started.
*/
- (void) didStartSuccessfully;
/**
* This method is called when an exception is thrown when trying to
* start the indoor location service.
*/
- (void) didFailStarting;
/**
* This method is called when a new position is available.
*
* @param location User position
*/
- (void) onLocation:(OYMLocationResult*)location;
/**
* This method is callen when a notification is triggered.
*
* @param notification Notification triggered
*/
- (void) onNotification:(OYMNotificationResult*)notification;
@optional
/**
* This method is called when the app has not the right authorisation for the Location Services.
*
* @param current Current Authorisation Permission
*/
- (void) locationAlwaysAuthorizationRequired:(CLAuthorizationStatus)current;
/**
* This method is called when the Location Services are disabled.
*/
- (void) locationServicesAreDisabled;
/**
* This method is called when the Core Blueooth Central Manager state has changed.
*
* @param state The new Core Blueooth Central Manager state
*/
- (void) centralManagerDidChangeState:(enum CBCentralManagerState)state;
@end
OYMLocationResult
对象包括以下字段
/** WGS84 Latitude */
@property (readonly) double latitude;
/** WGS84 Longitude */
@property (readonly) double longitude;
/** Number of iBeacons used */
@property (readonly) int used;
/** Position accuracy (meters) */
@property (readonly) double accuracy;
/** List including the longitude, latitude and accuracy of each iBeacon in sight */
@property (readonly) NSArray* found;
/** Floor number */
@property (readonly) int floorNumber;
/** Positioning type: kOYMIndoorLocationTypeNo, kOYMIndoorLocationTypeIbeacon, kOYMIndoorLocationTypeGps */
@property (readonly) int type;
/** Building name */
@property (readonly) NSString* buildingName;
/** Building ID */
@property (readonly) NSString* building;
/** Number of geofences */
@property (readonly) int geofences;
以下步骤是创建 goindoor 库的新实例
go = [OYMGoIndoor goIndoorWithBlock:^(id<GoIndoorBuilder> builder) {
[builder setAccount:account];
[builder setPassword:password];
[builder setConnectCallBack:callback];
}];
为了启动位置服务,需要向库提供一个符合 OYMLocationDelegate
协议的对象。
[go startLocate:delegate];
启动库后,当计算新的位置时,将使用委托。
退出应用程序
为了正确停止库,当库不再需要且位置服务应停止时,需要调用 stopLocate 方法。
[go disconnect];
创建路径
为了在两点之间创建路径,需要将这些点编码在 OYMRoutePoint
对象中。
- (OYMRoutePoint*) initWithX:(NSNumber*)newX andY:(NSNumber*)newY andFloornumber:(NSNumber*)fn andBuildingId:(NSString*)bId;
要获取 OYMRoute
对象,只需使用 computeRoute()
方法即可
OYMRoute* route = [go computeRouteFrom:start to:destination];
将位置投影到路径上
一旦计算了路径,就可以使用 OYMRoute
对象中的 getProjectionForLocation:(OYMLocationResult*)
方法将用户位置投影到已计算的路径上。该方法将提供一个 OYMRoutingResult
,其中包含用户在路径上的位置、一个表示用户是否远离路径的标志以及其他有用的信息。
显示室内地图
MapKit 集成
Goindoor 库包含一份可用账户的建筑列表。在每个 Building 对象中,它包含了该建筑的所有楼层,包括它们的瓦片提供者。为了在 MapKit 框架中显示室内地图重叠,框架包含一个辅助类 OYMTileOverlay
,它继承自 MKTileOverlay
。此对象可从 OYMFloor
类检索,并将其覆盖在 MKMapView
实例上。
tileOverlay = f.tileProvider;
[mapView addOverlay:tileOverlay level:MKOverlayLevelAboveLabels];
Google Maps 集成
Goindoor 还可以在 iOS 的 Google Maps 中使用。为了保证兼容性,需要包含 OYMFloor+GoogleMaps
类别,以便在当前仓库中可用。这个类别将提供一个类型为 GMSURLTileLayer
的 tileProviderGoogle
变量,以在 GMSMapView
中集成。假设要显示的 OYMFloor
为变量 floor
,且 map
变量已正确初始化,在 Google Maps 上覆盖室内瓦片应如下例所示。
GMSURLTileLayer *layer = floor.tileProviderGoogle;
layer.map = map;
退出应用
在退出应用之前,建议断开与服务器的连接。为此,应调用 disconnect
方法。
[go disconnect];