室内导航开发笔记

IndoorAtlas室内导航iOS版集成方法:

1.将IndoorAtlas.framework导入Xcode的Frameworks中。

2.选中TARGETS-->Build Phases-->Link Binary With Libraries 添加需要的系统框架(9个)

UIKit
CoreMotion
CoreLocation
Accelerate
CFNetwork
Security
SystemConfiguration 
Foundation
libz.dylib or libz.tbd (目前导入的是libz.tbd)

3.在需要的地方

#import <IndoorAtlas/IndoorAtlas.h>

4.添加C++标准库

选中PROJECT-->Build Settings-->Linking-->Other Linker Flags-->添加 -lstdc++

5.在Info.plist中添加字段,即时获取当前位置

<key>NSLocationAlwaysUsageDescription</key>
<string>Platform location requested for better indoor positioning experience.</string>

6.关闭Bitcode

选中PROJECT-->Build Settings-->Build Options-->设置Enable Bitcode为NO

 

配置完成,在indoorAtlas Maps中申请ApiKey和APISecret即可。

 

IndoorAtlas室内导航iOS版使用方法:

IndoorAtlas iOS SDK (2.0.2-beta-32)文档

引入协议IALocationManagerDelegate,验证kAPIKey和kAPISecret

self.manager = [IALocationManager new];

self.manager.delegate = self;

[self.manager setApiKey:kAPIKey andSecret:kAPISecret];

 可以预设一个地图,不设置也没有影响。

IALocation *location = [IALocation locationWithFloorPlanId:@"42cbf9d1-575d-4bb1-b725-c1c4ebc1aa63"];

self.manager.location = location;

实现方法 

- (void)indoorLocationManager:(IALocationManager *)manager didUpdateLocations:(NSArray *)locations;

- (void)indoorLocationManager:(IALocationManager *)manager didEnterRegion:(IARegion *)region;

先利用【didEnterRegion】方法获取进入的region(IARegion),region中region.identifier存储着floorplanId。

使用IAResourceManager和floorplanId可获得当前所在楼层的floorplan(IAFloorPlan)。【fetchFloorPlanWithId】

同时可以使用【fetchFloorPlanImageWithId】获取当前楼层的图片。

 

float scale = fmin(1.0, fmin(weakSelf.view.bounds.size.width / floorplan.width, weakSelf.view.bounds.size.height / floorplan.height));

 scale可确定在屏幕上显示的楼层图片的缩放比例

获取图片宽高与屏幕的比例 ,取比例小的边进行缩放,图片大于屏幕则缩放比例设定为屏幕最大显示。

 

使用CGAffineTransform进行UIImageview的变换

weakSelf.imageView.transform = CGAffineTransformIdentity;//恒等变换 相当于赋初值

CGAffineTransform t = CGAffineTransformMakeScale(scale, scale);

weakSelf.imageView.transform=t; //进行图片缩放

 

float size = floorplan.meterToPixelConversion;

//1米所占像素数

eg:floorplan.meterToPixelConversion=5   则一米对应5像素点

floorplan.pixelToMeterConversion1像素点对应的米数    1/meterToPixelConversion

导航的用户点是一个现实情况下一米的正方形  使用size转换成图片上的大小

 

得到floorplan后即可使用【didUpdateLocations】监听所在地点

NSArray中存储着IALocation,取最后一个

IALocation* loc = [locations lastObject];

 

IALocation中有location、floor、region三个属性。

@property (nonatomic, readonly, nullable) CLLocation *location;

CLLocation可以使用经度和纬度初始化,其他property由默认值填充

- (instancetype)initWithLatitude:(CLLocationDegrees)latitude
                       longitude:(CLLocationDegrees)longitude

 

 使用下面函数也可以进行全面的初始化

- (instancetype)initWithCoordinate:(CLLocationCoordinate2D)coordinate
                          altitude:(CLLocationDistance)altitude
                horizontalAccuracy:(CLLocationAccuracy)hAccuracy
                  verticalAccuracy:(CLLocationAccuracy)vAccuracy
                         timestamp:(NSDate *)timestamp

 

 CLLocationCoordinate2D中存有经度和纬度信息,都是double类型

typedef struct { CLLocationDegrees latitude; CLLocationDegrees longitude; } CLLocationCoordinate2D;
typedef double CLLocationDegrees; 

使用IAFloorPlan将精确的经纬度转换成图片上的像素点,将代表人的小方块添加到地图上即可

CGPoint point = [self.floorPlan coordinateToPoint:loc.location.coordinate];//经纬度转换成图片的像素点

 

注意事项

iOS8中定位服务CLLocaitonManager使用有一些变动

首先在 .h文件 中定义一个属性:

@property (nonatomic, strong) CLLocationManager *locationManager;

 并且遵守CLLocationManagerDelegate 

@interface testViewController: UIViewController<CLLocationManagerDelegate>

之后在 viewDidLoad 中创建这个变量:

   if (self.locationManager == nil) {  
        self.locationManager = [[CLLocationManager alloc]init];
    }

    self.locationManager.delegate = self;
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 8.0) {
        [self.locationManager requestWhenInUseAuthorization];
    }

    [self.locationManager startUpdatingLocation];

[self.locationManager requestWhenInUseAuthorization]; 这么做就是为了实现第一次打开应用询问用户是否允许该应用使用定位服务。

需要在info.plist中添加一个Key:NSLocationWhenInUseUsageDescription Value为希望显示的文字 

最后实现协议的方法

- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray *)locations{
    CLLocation *newLocation = [locations lastObject];
    NSLog(@"开始定位:%@",newLocation);
    [manager stopUpdatingHeading];
    if (self.data == nil) {
        float longitude = newLocation.coordinate.longitude;
        float latitude =  newLocation.coordinate.latitude;


- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error{
    NSLog(@"定位错误");
}

 

 

 

 

你可能感兴趣的:(室内导航开发笔记)