在 iOS7以后,手机上就可以实现3D 地图效果了。其实,实现3D 地图效果并不难,就是几行代码的事。
在 iOS7中引入了一个新的 MKMapCamera 类,它将一个 MKMapCamera 对象添加到地图上,在指明位置、角度和方向后,呈现3D 效果。对于角度、方法等的调整使用一些属性:
方法 | 功能 |
centerCoordinate | 地图视图的中心坐标 |
heading | 方向 |
pitch | 角度 |
altitude | 海拔 |
看代码:
#import "ViewController.h"
#import <MapKit/MapKit.h>
@interface ViewController ()
{
MKMapView *mapView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:mapView];
mapView.centerCoordinate = CLLocationCoordinate2DMake(37.78275123, -122.40416442);
mapView.showsBuildings = YES;
mapView.camera.altitude = 200;//海拔
mapView.camera.pitch = 70;//角度
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end