准备工作
概述
街景SDK(iOS)是一套基于iOS5.1.1及以上设备的应用程序接口,通过该接口,您可以方便地访问腾讯街景服务,构建自己街景应用程序
编译配置需求:
- Xcode6.0 及以上
- iOS SDK8.0 及以上
- Deployment Target 5.1及以上
完整的Demo例程可参考IOS_Panorama
引入街景引擎
1.添加引擎framework
在TARGETS -> Build Phases -> Link Binary with Libraries 点击“+”,弹出添加列表后,点击”Add Other…”,从frameworks文件夹中添加QPanoramaKit.framework和WebP.framework到工程中

2.添加bundle文件
在工程界面右键弹出菜单中选择"Add Files To...”,从文件夹frameworks->QPanoramaKit.framework->Resources中将资源文件QPanoramaKit.bundle添加到工程中,在弹出窗口中勾选"Copy items into destination group's folder(if needed)”。

3.添加所依赖的系统库
在TARGETS-Build Phases-Link Binary with Libraries 点击”+",弹出添加列表后,选择添加
1.libstdc++.6.dylid
2.libz.dylib

4.添加需要的编译选项
在TARGETS-Build Settings-Other Linker Flags 中添加如下内容: -ObjC 。

申请和添加key
1.申请用户key
1.访问https://lbs.qq.com/dev/console/key/add,点击右上角申请秘钥,输入qq账号登录
2.填写应用名称,描述,验证码,阅读并同意使用条款
3.申请完成后,点击"我的秘钥"按钮,得到申请的key

2.在项目中添加key
在使用街景SDK时,需要对应用做Key机制验证,如果街景不添加key,街景将不能运行,控制台会显示没有key的错误日志,在街景初始化之前将您在官网上申请的Key添加到如下:
3.示例代码
1 | [[QPanoServices sharedServices] setApiKey:@ "您的key" ]; |
显示街景
在您的ViewController.h文件中添加QPanoramaView的创建代码。
1 2 3 4 5 6 7 8 | #import <UIKit/UIKit.h> #import <QPanoramaKit/QPanoramaKit.h> @interface ViewController:UIViewController<QPanoramaViewDelegate> @property (nonatomic, strong) QPanoramaView *panoramaView; @end |
在您的ViewController.m文件添加实例化PanoramaView的代码。
1 2 3 4 5 6 7 | self.panoramaView = [QPanoramaView panoramaViewWithFrame:CGRectMake( 0, 0, self.view.frame.size.width, self.view.frame.size.height - kQPanoramaDemoToolBarHeight) nearCoordinate:CLLocationCoordinate2DMake(39.908116, 116.410368) radius:100]; [self.panoramaView setDelegate:self]; [self.view addSubview:self.panoramaView]; |
添加标注
修改您的viewController.h文件,添加以下代码,使您的ViewController实现QPanoramaViewDelegate协议:
1 2 3 4 5 6 7 | #import <QPanoramaKit/QPanoramaKit.h> @interface ViewController ()<QPanoramaViewDelegate> @property (nonatomic, strong) QPanoramaView *panoramaView; @end |
iOS SDK 提供的街景地图标注为QPanoPointAnnotation类,街景地图SDK接口提供添加单个标注或者一个标注数组。添加一个标注的示例代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 | - ( void )addAnnotation { QPanoPointAnnotation *annotation = [[QPanoPointAnnotation alloc] init]; static double lat = 39.909143289806735; static double lng = 116.41039596443157; annotation.coordinate = CLLocationCoordinate2DMake(lat,lng); annotation.height = 0; [annotation setTitle:@ "标题" ]; [annotation setSubtitle:@ "上面是标题" ]; [self.panoramaView addAnnotation:annotation]; } |
标注样式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | - (QPanoAnnotationView *)panoramaView:(QPanoramaView *) panoramaView viewForAnnotation:(id<QPanoAnnotation>)annotation { static NSString *pointReuseIndetifier = @ "pointReuseIndetifier" ; QPanoAnnotationView *annotationView = (QPanoAnnotationView*)[panoramaView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier]; if (annotationView == nil) { annotationView = [[QPanoAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier]; [annotationView setImage: [UIImage imageNamed:@ "QPanoramaKit.bundle/marker_selected.png" ]]; } annotationView.animatesDrop = YES; annotationView.canShowCallout = YES; annotationView.leftCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; return annotationView; } |
效果如图所示:

删除标注
调用panoramaView 对象的removeAnnotation:方法删除指定的标注;或者调用 removeAnnotations:方法删除指定的标注对象数组,以下为删除标注数组的示例代码如下:
1 2 3 4 5 6 | - ( void )removeAnnotation { NSArray *annotations = [self.panoramaView annotations]; [self.panoramaView removeAnnotations:annotations]; } |
街景动画
1.QPanoramaCamera
该类用于控制QPanoramaView的视角,和具体的街景场景点无关。创建QPanoramaCamera,使用 -(instancetype)initWithOrientation:(QOrientation)orientation zoom:(float)zoom方法进行初始化。其中QOrientation为偏航俯仰角结构体,偏航角heading区间是 -180 到 180,俯仰角Pitch区间 -90 到 10。Zoom为缩放,级别key [0, 2], 默认 0。示例代码如下:
1 2 3 4 5 6 7 | - ( void )cameraAnimation { QPanoramaCamera *camera = [[QPanoramaCamera alloc] initWithOrientation:QOrientationMake(110, -10) zoom:1]; [self.panoramaView animateToCamera:camera animationDuration:2]; } |
2.QPanoramaCameraUpdate
该类用于场景视角更新 。创建QPanoramaCameraUpdate,如下的例子为创建偏航角(原始heading角度+deltaHeading偏航角插值)。示例代码如下:
1 2 3 4 5 6 | -( void )cameraUpdateAnimation { QPanoramaCameraUpdate *update = [QPanoramaCameraUpdate rotateBy:30]; [self.panoramaView updateCamera:update animationDuration:3]; } |
切换场景
1.ID移动
街景SDK可以实现移动到指定panoramaID的位置,示例代码如下:
1 2 3 4 5 | - ( void )moveToPanoramaID { [self.panoramaView moveToPanoramaID:@ "10011029140710152547600" ]; } |
2. 经纬度移动
街景SDK还可以实现移动到指定的位置,示例代码如下:
1 2 3 4 5 6 | - ( void )moveToCoordinate { [self.panoramaView moveToNearCoordinate: CLLocationCoordinate2DMake(39.999832, 116.312808)]; } |