Prerequisite
For all of our examples, you will need:
- an API key,
- knowledge in Swift/iOS development,
- one style (default)
Get the library
Use MapMetrics-SDK. The MapMetrics-iOS pod is abandoned.
This page used to install MapMetrics-iOS ~> 0.0.3. Do not use it. That pod stopped at 0.0.3, and its repository has no release newer than 1.0.0.
The current iOS SDK is MapMetrics-SDK, at 2.0.1.
This is a billing difference, not a version-number preference. Up to and including 2.0.0, the SDK sent its opening style-and-tile wave before the async map-session create landed, so those requests carried only the style token and were billed once per tile instead of once per map load — 8+ units on a cold start. Nothing looks wrong when that happens: the map renders correctly and the cost is silent. 2.0.1 is a floor, not a preference.
Installation (CocoaPods)
Add this to your Podfile:
target 'YourApp' do
pod 'MapMetrics-SDK', '~> 2.0.1'
endRun:
pod installRequired Build Settings (Sandbox Fix)
To prevent rsync.samba deny(1) errors, users must add these settings:
Option A: Automatic Fix (via Podfile)
Add to your Podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# Disable sandbox restrictions
config.build_settings['ENABLE_USER_SCRIPT_SANDBOXING'] = 'NO'
end
end
endThen run:
pod installOption B: Manual Fix (Xcode Settings)
- Open your project in Xcode.
- Go to Target → Build Settings.
- Search for
ENABLE_USER_SCRIPT_SANDBOXING. - Set to NO for all configurations (Debug/Release).
Verify Installation
Import in your code:
import MapMetricsClean Build (if issues persist):
rm -rf ~/Library/Developer/Xcode/DerivedData/*Troubleshooting
| Issue | Solution |
|---|---|
| Sandbox deny(1) errors | Ensure ENABLE_USER_SCRIPT_SANDBOXING=NO is set. |
pod install fails | Delete Pods/ and Podfile.lock, then retry. |
| Version conflicts | Run pod update MapMetrics. |
Example Podfile (Complete)
platform :ios, '12.0'
target 'YourApp' do
use_frameworks!
pod 'MapMetrics-SDK', '~> 2.0.1'
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_USER_SCRIPT_SANDBOXING'] = 'NO'
end
end
end
endExample Usage
Here's how to integrate MapMetrics into your project:
class ViewController: UIViewController, MLNMapViewDelegate {
var mapView: MLNMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView = MLNMapView(
frame: view.bounds,
styleURL: URL(string: "https://gateway.mapmetrics-atlas.net/styles/?fileName=YOUR_STYLE_ID/YOUR_STYLE.json&token=YOUR_API_KEY")
)
mapView.delegate = self
view.addSubview(mapView)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.delegate = self
// This is a better starting position
let center = CLLocationCoordinate2D(latitude: 20.0, longitude: 0.0) // More centered globally
mapView.setCenter(center, zoomLevel: 2, animated: false) // Lower zoom to see more area
view.addSubview(mapView)
}
}