• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

高德地图api使用inswift

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

1,导入库,具体方法参考官方文档http://developer.amap.com/api/ios-sdk/guide/project/

其中特别注意:AMap.bundle按照要求,拖进来选择copy if needed

 

2,修改Build Setting的4个地方的配置信息

以上两步操作,我想objc中引入到的地图也是这么操作的

3,在Header-Bridging.h中import你想导入的类

经几番折腾得出结论:swift在引入高德地图时还是存在bug,等待苹果修复中。现在只能用objc了。以下是地图的最基本功能,高德地图集成大量api,都必须在这个基础上拓展。

//
//  MapViewController.h
//  SwiftStudy3
//
//  Created by dongway on 14-7-9.
//  Copyright (c) 2014年 dongway. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "MAMapKit/MAMapKit.h"

@interface MapViewController : UIViewController<MAMapViewDelegate>

@property(nonatomic) MAMapView *mapView;

@end
//
//  MapViewController.m
//  SwiftStudy3
//
//  Created by dongway on 14-7-9.
//  Copyright (c) 2014年 dongway. All rights reserved.
//

#import "MapViewController.h"

//此处坐标为长沙某地坐标
#define DeviceFrame [UIScreen mainScreen].applicationFrame
#define Latitude 28.1658601239483
#define Longitude 112.947241748764

@interface MapViewController ()

@end

@implementation MapViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // Do any additional setup after loading the view.
    self.mapView = [[MAMapView alloc] initWithFrame:DeviceFrame];
    self.mapView.delegate = self;
    self.mapView.visibleMapRect = MAMapRectMake(220880104.0, 101476980.0,  9249.0, 13265.0);
    self.mapView.centerCoordinate = CLLocationCoordinate2DMake(Latitude, Longitude);
    
    NSMutableArray *annotations = [[NSMutableArray alloc] init];
    MAPointAnnotation *point1 = [[MAPointAnnotation alloc] init];
    point1.coordinate = CLLocationCoordinate2DMake(Latitude, Longitude);
    [annotations addObject:point1];
    [self.mapView addAnnotations:annotations];
    
    [self.view addSubview:self.mapView];
    
  }

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(MAAnnotationView*)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation
{
    if ([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        static NSString *pointReuseIndetifier = @"pointReuseIndetifier";
        MAPinAnnotationView*annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier];
        if (annotationView == nil)
        {
            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIndetifier];
            annotationView.canShowCallout= NO;      //设置气泡可以弹出,默认为NO
            annotationView.animatesDrop = YES;       //设置标注动画显示,默认为NO
            annotationView.draggable = NO;           //设置标注可以拖动,默认为NO
//            annotationView.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];  //设置气泡右侧按钮
        }
        return annotationView;
    }
    return nil;
}

@end

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
WelcometoSwift(苹果官方Swift文档初译与注解六)---35~44页(第一章完) ...发布时间:2022-07-13
下一篇:
hello Kotlin (android 的swift)发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap