IOS使用高德地图的基本DEMO

Podfile文件

platform :ios, '8.0'
target 'yourapp' do
pod 'AMapLocation'
end

然后,pod install

Info.plist

<key>NSLocationAlwaysUsageDescription</key>
<string>家教100 请求后台定位权限</string>
<key>UIBackgroundModes</key>
<array>
    <string>location</string>
</array>

说明:第一项是请求后台定位权限的描述,第二项是在ios9中必须要使用的

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

忘了高德的接口是http的了,也不知道ios10要怎么适配,知道的人告诉我一下

AMapDemoSwift-Bridging-Header.h 文件

#ifndef AMapDemoSwift_Bridging_Header_h
#define AMapDemoSwift_Bridging_Header_h
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <AMapLocationKit/AMapLocationKit.h>

#endif /* AMapDemoSwift_Bridging_Header_h */

注意做好桥接

AppDelegate.swift文件中

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    AMapServices.sharedServices().apiKey = "yourappkey"
    return true
}

在实现文件中需要实现AMapLocationManagerDelegate协议,主要的方法是


var locationManager:AMapLocationManager!

// 配置,并非delegate中的方法
private func configLocationManager() {
    self.locationManager = AMapLocationManager()
    self.locationManager.delegate = self
    self.locationManager.pausesLocationUpdatesAutomatically = false
    self.locationManager.allowsBackgroundLocationUpdates = false
}
// 发生了错误
func amapLocationManager(manager:AMapLocationManager, didFailWithError error:NSError) {
   print("error:\(error)")
}

// 更新定位
func amapLocationManager(manager:AMapLocationManager, didUpdateLocation location:CLLocation) {
    print("lat:\(location.coordinate.latitude),lng:\(location.coordinate.longitude)")
    self.locationManager.stopUpdatingLocation()
}

在启动的时候调用

self.configLocationManager()
self.locationManager.startUpdatingLocation()

暂时就是这样吧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值