Map.ir Map Kit
Map.ir Map Kit 是一个基于 Mapbox 框架的交互式地图,提供 Map.ir 标签。
特性
- 支持 Swift 和 Objective-C
- 可定制的地图和手势。
- 界面类似于 Apple 的 MapKit。
- 支持 Interface builder。
- 根据系统主题的更新自动切换到暗黑模式(日落/日出时)。
- 所有这些都使用 Map.ir 的向量和栅格地图标签。
示例
要查看示例应用程序,首先在终端中运行 git clone https://github.com/map-ir/mapir-ios-maps-sdk
。打开 MapirMapKit.xcodeproj
。构建并运行 Mapir MapKit Example
目标。每个视图控制器都展示地图的一个功能。更多示例将很快可用。
安装
CocoaPods
Map.ir Map Kit 可通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile
pod 'MapirMapKit'
Carthage
Carthage 是一个去中心化的依赖管理器,可以构建您的依赖关系并提供二进制框架。
要使用 Carthage 将 Map.ir Map Kit 集成到您的 Xcode 项目中,请在其 Cartfile
中指定。
github "map-ir/mapir-ios-maps-sdk"
运行 carthage update
以构建框架,并将构建的 MapirLiveTracker.framework
和 Mapbox.framework
拖放到您的 Xcode 项目中。
在您的应用程序目标的“构建阶段”设置标签页中,点击“+”图标,选择“新建运行脚本阶段”,并添加以下行
/usr/local/bin/carthage copy-frameworks
将 MapirMapKit.framework
和 Mapbox.framework
添加为输入文件
$(SRCROOT)/Carthage/Build/iOS/MapirMapKit.framework
$(SRCROOT)/Carthage/Build/iOS/Mapbox.framework
$(SRCROOT)/Carthage/Build/iOS/MapboxMobileEvents.framework
有关详细信息,请参阅Carthage 入门步骤 4、5 和 6。
使用方法
此 SDK 兼容 Swift 和 Objective-C 编程语言,使用 iOS 9.0 或更高版本。
首先导入 Map.ir MapKit。
import MapirMapKit
#import <MapirMapKit/MapirMapKit.h>
为了使用 Map.ir 标识,您需要在项目的 Info.plist 文件中指定您的 API 密钥,使用 MAPIRAPIKey
(旧版本使用 MAPIAccessToken
密钥。SDK 仍然支持此密钥,但我们建议将密钥更新为 MAPIRAPIKey
)。
<key>MapirAPIKey</key>
<string><YOUR_API_KEY></string>
然后使用 SHMapView
的初始化器来创建其实例。SHMapView 是 MGLMapView
的子类,具有 Map.ir 标识。要接收与地图相关的更新,例如有关样式加载的事件,您应指定一个视图的代理对象,在创建 SHMapView
实例之后立即设置代理类。要创建 SHMapView
实例并指定其 delegate
,请参阅以下代码
class ViewController: UIViewController {
var mapView: SHMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView = SHMapView(frame: view.bounds)
mapView.delegate = self
}
...
}
extension ViewController: SHMapViewDelegate {
// Define delegate methods here.
}
在视图控制器的头文件中
@interface ViewController : UIViewController <SHMapViewDelegate>
@property (nonatomic, strong) SHMapView *mapView;
@end
在视图控制器的实现文件中
@implementation
- (void)viewDidLoad
{
[super viewDidLoad];
mapView = [[SHMapView alloc] initWithFrame:self.view.bounds];
[mapView setDelegate:self];
}
// Define delegate methods here.
@end
贡献
欢迎贡献。