概述
ViewController.swift
//
//
ViewController.swift
//
baidumapfirsttest
//
//
Created by targetcloud on 2016/11/16.
//
Copyright © 2016年 targetcloud. All rights reserved.
//准备:
//下载包
//http://wiki.lbsyun.baidu.com/cms/iossdk/sdk/BaiduMap_IOSSDK_v3.1.0_All.zip
//生成密钥(API控制台) http://lbsyun.baidu.com/apiconsole/key
//wRRSuxGeEiD1yiPv8ej4XucCnTbjtQfR
//开始集成
//1 add ATS
//2 拖包
//BaiduMapAPI_Base.framework
//BaiduMapAPI_Cloud.framework
//BaiduMapAPI_Location.framework
//BaiduMapAPI_Map.framework
//BaiduMapAPI_Radar.framework
//BaiduMapAPI_Search.framework
//BaiduMapAPI_Utils.framework
//3 添加系统库的依赖在Linked Frameworks and Libraries
//CoreLocation.framework
//QuartzCore.framework
//OpenGLES.framework
//SystemConfiguration.framework
//CoreGraphics.framework
//Security.framework
//libsqlite3.0.tbd
//CoreTelephony.framework
//libstdc++.6.0.9.tbd
//4 在Build Settings 查找框中输入other link,然后在找到下面列表中的 Other Linker Flags 中输入-ObjC
//5 拖入BaiduMapAPI_Map.framework-> Resources-> mapapi.bundle 到工程中
//6 创建桥接文件(OC 到 swift), 在BMKSwiftDemo-Bridging-Header.h中输入
//#import <BaiduMapAPI_Base/BMKBaseComponent.h>//引入base相关所有的头文件
//#import <BaiduMapAPI_Map/BMKMapComponent.h>//引入地图功能所有的头文件
//#import <BaiduMapAPI_Search/BMKSearchComponent.h>//引入检索功能所有的头文件
//#import <BaiduMapAPI_Cloud/BMKCloudSearchComponent.h>//引入云检索功能所有的头文件
//#import <BaiduMapAPI_Location/BMKLocationComponent.h>//引入定位功能所有的头文件
//#import <BaiduMapAPI_Utils/BMKUtilsComponent.h>//引入计算工具所有的头文件
//#import <BaiduMapAPI_Radar/BMKRadarComponent.h>//引入周边雷达功能所有的头文件
//#import <BaiduMapAPI_Map/BMKMapView.h>//只引入所需的单个头文件
//7配置桥接文件
//在 Build Setting 查找框中输入brid,在下面的列表中找到Objective-C Bridging Header 中输入baidumapfirsttest/BMKSwiftDemo-Bridging-Header.h
//8 info.plist 添加Bundle display name
//9 添加代码
import UIKit
class ViewController: UIViewController {
var _mapView: BMKMapView?
override func viewDidLoad() {
super.viewDidLoad()
_mapView = BMKMapView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
self.view.addSubview(_mapView!)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
_mapView?.viewWillAppear()
//
_mapView?.delegate = self // 此处记得不用的时候需要置nil,否则影响内存的释放
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
_mapView?.viewWillDisappear()
_mapView?.delegate = nil // 不用时,置nil
}
}
AppDelegate.swift
//
//
AppDelegate.swift
//
baidumapfirsttest
//
//
Created by targetcloud on 2016/11/16.
//
Copyright © 2016年 targetcloud. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var _mapManager: BMKMapManager?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
_mapManager = BMKMapManager()
// 如果要关注网络及授权验证事件,请设定generalDelegate参数
let ret = _mapManager?.start("wRRSuxGeEiD1yiPv8ej4XucCnTbjtQfR", generalDelegate: nil)
if ret == false {
NSLog("manager start failed!")
}
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
最后
以上就是虚拟小兔子为你收集整理的swift地图定位(十九)集成百度地图的全部内容,希望文章能够帮你解决swift地图定位(十九)集成百度地图所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复