按照说明稳定获取apiKey 引用11个库文件,
#import "ViewController.h"
#import <MAMapKit/MAMapKit.h>
@interface ViewController ()<MAMapViewDelegate>
{
MAMapView *_mapView;
CLLocation *_userLocation;
}
@end
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 2c37b41189e673357bf55d23edeeed7c
[MAMapServices sharedServices].apiKey = @"2c37b41189e673357bf55d23edeeed7c";
_mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, maiScr.width, maiScr.height)];
_mapView.delegate = self;
[self.view addSubview:_mapView];
/********************** 上边是地图的显示 *************************************/
//打开定位
_mapView.showsUserLocation=YES;
_mapView.userTrackingMode=MAUserTrackingModeFollowWithHeading;
[_mapView setZoomLevel:16.1 animated:YES];
}
//当位置更新时,会进定位回调,通过回调函数,能获取到定位点的经纬度坐标,示例代码如下
//这个函数可以用于地图回归当前坐标原点
-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation
{
if (updatingLocation) {
//打印当前经纬度
// NSLog(@"latitude : %f ,longitude : %f",userLocation.coordinate.latitude,userLocation.coordinate.longitude);
/****************** CLLocation类创建的userLocation赋值给当前view中心点即可 *********************/
_userLocation=userLocation.location;
_mapView.centerCoordinate=_userLocation.coordinate;
}
}