iOS 开发,iOS 高德地图开发者怎么在视线内显示所有的标注

iOS使用高德地图趟过的坑([MAMapKit] apiKey为空,请检查key是否正确设置)_IOS开发-织梦者
当前位置:&>&&>& > iOS使用高德地图趟过的坑([MAMapKit] apiKey为空,请检查key是否正确设置)
iOS使用高德地图趟过的坑([MAMapKit] apiKey为空,请检查key是否正确设置)
首先如果你只引入高德地图(3DMAP)那么在申请的Key是没有问题的,只要在AppDelegate中设置
[AMapServicessharedServices].apiKey = @“”;
如果引入导航SDK,就不用在引入高德地图的SDK,因为导航SDK已经支持地图SDK的功能,但是如果你还是在AppDelegate里设置
[AMapServicessharedServices].apiKey
= @“你的key”这时运行你的App就会出现[MAMapKit]
apiKey为空,请检查key是否正确设置我的解决方法是在初始化MapView的ViewDidLoad方法里设置一下apiKey。
<img alt="iOS使用高德地图趟过的坑([MAMapKit] apiKey为空,请检查key是否正确设置)" src="/d/file/shujuku/jr03be3n5tu.png"
以上就是iOS使用高德地图趟过的坑([MAMapKit] apiKey为空,请检查key是否正确设置)的全文介绍,希望对您学习和使用ios应用开发有所帮助.
这些内容可能对你也有帮助
更多可查看IOS开发列表页。
猜您也会喜欢这些文章【IOS开发】地图开发,自定义标注
网上好多都是抄来抄去,折腾了我半天。后来看文档终于明白了。。真正的代码如下:
其中主要用到代理方法:viewForAnnotation以及MKPinAnnotationView这个地图标注。。
其中MKPinAnnotationView
&和&MKAnnotationView 的差别请自行百度。
func mapView(mapView:MKMapView!, viewForAnnotation
annotation: MKAnnotation!) -& MKAnnotationView! {
//发现是定位标注的话就返回空
if annotation
is MKUserLocation
& & //return nil so map view draws "blue dot" for standard user
& & return nil
let reuseId =
var pinView =
mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView ==
& & pinView = MKPinAnnotationView(annotation:
annotation, reuseIdentifier: reuseId)
& & pinView!.canShowCallout = true
& & pinView!.animatesDrop = true
& & pinView!.pinColor = .Purple
& & pinView!.image = UIImage(named: "del_icon@2x.png")
& & var rightButton: AnyObject! = UIButton.buttonWithType(UIButtonType.DetailDisclosure)
rightButton.titleForState(UIControlState.Normal)
rightButton.addTarget(self, action: "rightButtonTapped:",
forControlEvents: UIControlEvents.TouchUpInside)
& & pinView!.rightCalloutAccessoryView =
rightButton as! UIView
&&var leftImageV:UIImageView = UIImageView(frame: CGRect(x: jianxi, y: jianxi, width: 20, height: 20))
leftImageV.image = UIImage(named: "del_icon@2x.png");
& & pinView!.leftCalloutAccessoryView =
leftImageV;
& & pinView!.annotation = annotation
return pinView
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。3016人阅读
高德地图(1)
如何使用iOS SDK进行开发
LBS:基于位置的服务(Location Based Services)
准备成为高德开发者
&1.访问 /console/key/
&2.注册高德开发者账号并成为开发者
&3.为您的app申请依个key
详细请查看官方文档(API)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
第一步:配置工程(两种)
& & &第一种:手工配置&
& & & & & & & & & & & & & & & 详细:/api/ios-sdk/guide/buildproject/
& & 第二种 :使用第三方库管理工具
& & & & & & & & & 安装CocoaPods教程(官方指南)
& & & & & & & & & & & & & & & & & & /article/cocoapods-intall-usage
我们主要介绍自动化配置
& & 在我们的app中生成依个podfile文件
在 文件中加入(**注意2D地图和3D地图不能同时使用)
od 'AMap3DMap' #3D地图SDK
pod 'AMap2DMap' #2D地图SDK(2D地图和3D地图不能同时使用)
pod 'AMapSearch' #搜索服务SDK
然后进行下载
然后打开后缀为.xcworkspace工程
代码如下/*主要内容
1.显示地图
2.使用MAMapView定位功能{
有四步:第一步: 打开定位也就是showUserLocation属性
第二步: iOS8以上的系统需要在info.plist添加字段,如果你只需要在用户使用app时,打开定位。你只需要添加NSLocationWhenInUseUsageDescription这个字段,如果你在用户不使用app时还需要定位时,那么就需要添加NSLocationAlwaysUsageDescription这个字段
第三步:获取到定位点的经纬度坐标
当位置更新时,会进定位回调,通过MAMapView的代理回调函数,能获取到定位点的经纬度坐标
-(void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation
updatingLocation:(BOOL)updatingLocation
第四步:定位的模式(有3种,也是MAMapView的属性)
定位图层有3种显示模式,分别为:
MAUserTrackingModeNone:不跟随用户位置,仅在地图上显示。
MAUserTrackingModeFollow:跟随用户位置移动,并将定位点设置成地图中心点。
MAUserTrackingModeFollowWithHeading:跟随用户的位置和角度移动。
3.逆地理编码(把地理坐标编码成地址,把用户当前地址显示出来)
使用 search来实现地理编码的查询接口和逆地理编码查询的接口进行编码的实现
#import &ViewController.h&
//准备工作第一步 首先引入头文件
#import &MAMapKit/MAMapKit.h&
#import &AMapSearchKit/AMapSearchAPI.h&
//准备工作第二步 协议 定义一个宏 标识KEY
#define APIKey
@&2dbcec0dc4bc45e4b11c78ff&
@interface ViewController ()&MAMapViewDelegate&
//设置私有地图变量
MAMapView *_mapV
UIButton *_locationBU
//初始化search对象
AMapSearchAPI *_
//声明一个变量
CLLocation *_currentL
//准备工作第三步 在ViewController.m文件相应的方法中进行地图初始化
@implementation ViewController
// 代码实现第一步:MAMapView(初始化地图)
一个可嵌入的地图对象
功能:可以用来显示地图和对地图内容进行操作
初始化地图时,一般需要指定地图嵌入的位置和大小
- (instancetype)initWithFrame:(CGRect)
主要的属性:(有两个)
1:中心经纬度坐标CenterCoordinate (指的是地图中心点的位置它的经纬度坐标)
@property (nonatomic)CLLocationCoordinate2D centerC
2:缩放级别ZoomLevel (指的是在固定的View大小范围之内显示的地图范围是多少,缩放级别越小,显示地图范围越大)
@property (nonatomi) CGFloat zoomL
@property (nonatomic) CGPoint compassO
@property (nonatomic) CGPoint scaleO
- (void)initMapView{
[MAMapServices sharedServices].apiKey = APIK
_mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
设置地图的代理 和两个插件的位置
_mapView.delegate =
_passOrigin = CGPointMake(_passOrigin.x, 22);
_mapView.scaleOrigin = CGPointMake(_mapView.scaleOrigin.x, 22);
[self.view addSubview:_mapView];
// 此时运行时 APIkEY 会有一个对话框告诉你APIKey为空
//打开用户定位
_mapView.showsUserLocation = YES;
- (void)initSearch{
//也需要使用KEY(可以与MAMapViewKEY相同)
_search = [[AMapSearchAPI alloc] initWithSearchKey:APIKey Delegate:self];
接下来需要获取到用户当前所在地的经纬度
需要使用MAMapView的回调方法
//位置或者设备方向更新后,会调用此函数。
//参数mapView 地图 view。
//userLocation 用户定位信息(包括位置与设备方向等数据)。
- (void)mapView:(MAMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation{
NSLog(@&%@&,userLocation.location);
//将用户位置信息存入变量中
_currentLocation = userLocation.
NSLog(@&%d&,updatingLocation);
//进行逆地理编码请求
- (void)reGeoAction{
if (_currentLocation) {
AMapReGeocodeSearchRequest *request = [[AMapReGeocodeSearchRequest alloc] init];
request.location = [AMapGeoPoint locationWithLatitude:_currentLocation.coordinate.latitude longitude:_currentLocation.coordinate.longitude];
//逆地理编码搜索请求
[_search AMapReGoecodeSearch:request];
//同样Search也有回调方法
- search:error:
通知查询成功或失败的回调函数。已废弃。 更多...
- searchRequest:didFailWithError:
当请求发生错误时,会调用代理的此方法。 更多...
- onPlaceSearchDone:response:
POI 查询回调函数。 更多...
- onNavigationSearchDone:response:
路径查询回调函数。 更多...
- onInputTipsSearchDone:response:
输入提示查询回调函数。 更多...
- onGeocodeSearchDone:response:
地理编码查询回调函数。 更多...
- onReGeocodeSearchDone:response:
逆地理编码查询回调函数。 更多...
- onBusLineSearchDone:response:
公交线路查询回调函数。 更多...
- onBusStopSearchDone:response:
公交站点查询回调函数。 更多...
- onDistrictSearchDone:response:
行政区域查询回调函数。 更多...
- (void) onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response{
NSLog(@&request:%@&,request);
NSString *title = response.regeocode.addressComponent.
if (title.length == 0) {
title = response.regeocode.addressComponent.
_mapView.userLocation.title =
_mapView.userLocation.subtitle = response.regeocode.formattedA
//MAMapView的回调方法:当地图上的标记被选中时
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view{
//判断当前选中定位annotation的时候进行逆地理编码
if ([view.annotation isKindOfClass:[MAUserLocation class]]){
[self reGeoAction];
NSLog(@&%@&,view.annotation);
- (void)initControls{
_locationBUtton = [UIButton buttonWithType:UIButtonTypeCustom];
_locationBUtton.frame = CGRectMake(20, CGRectGetHeight(_mapView.bounds) - 80, 40, 40);
_locationBUtton.backgroundColor = [UIColor purpleColor];
[_locationBUtton addTarget:self action:@selector(locationAction) forControlEvents:UIControlEventTouchUpInside];
[_mapView addSubview:_locationBUtton];
//主要作用,修改定位模式
- (void)locationAction{
if(_mapView.userTrackingMode != MAUserTrackingModeFollow)
[_mapView setUserTrackingMode:MAUserTrackingModeFollowWithHeading animated:YES];
NSLog(@&%ld&,_mapView.userTrackingMode);
//当改变定位模式时回调的方法
- (void)mapView:(MAMapView *)mapView didChangeUserTrackingMode:(MAUserTrackingMode)mode animated:(BOOL)animated{
NSLog(@&%ld===%d&,mode , MAUserTrackingModeFollowWithHeading);
if (mode == MAUserTrackingModeFollow){
[_locationBUtton setImage:[UIImage imageNamed:@&icon-72@2x&] forState:UIControlStateNormal];
- (void)viewDidLoad {
[super viewDidLoad];
[self initMapView];
[self initSearch];
[self initControls];
1、iOS9为了增强数据访问安全,将所有的http请求都改为了https,为了能够在iOS9中正常使用地图SDK,请在&Info.plist&中进行如下配置,否则影响SDK的使用。
&key&NSAppTransportSecurity&/key&
&key&NSAllowsArbitraryLoads&/key&
2、在iOS9中为了能正常调起高德地图App的功能,必须在&Info.plist&中将高德地图App的URL scheme列为白名单,否则无法调起,配置如下:
&key&LSApplicationQueriesSchemes&/key&
&string&iosamap&/string&
// Do any additional setup after loading the view, typically from a nib.
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:14781次
排名:千里之外
原创:12篇
(1)(2)(2)(3)(6)(1)(2)

我要回帖

更多关于 ios高德地图开发 的文章

 

随机推荐