Prerequisite
For all of our examples, you will need:
- an API key,
- knowledge in Swift/iOS development,
- one style (default)
Get the library
There are several ways to get this library:
- from the github repository (https://github.com/MapMetrics/MapMetrics-iOS)
- from swift package https://github.com/MapMetrics/MapMetrics-iOS
- from cocoapods.org
Installation (CocoaPods)
Add this to your Podfile:
ruby
target 'YourApp' do
pod 'MapMetrics-iOS', '~> 0.0.1' # Use the latest version
# OR
pod 'MapMetrics-iOS', :git => 'https://github.com/MapMetrics/MapMetrics-iOS', :tag => '0.0.1'
end
Run:
bash
pod install
Required 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:
ruby
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
end
Then run:
bash
pod install
Option 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:
swift
import MapMetrics
Clean Build (if issues persist):
bash
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)
ruby
platform :ios, '12.0'
target 'YourApp' do
use_frameworks!
pod 'MapMetrics-iOS', '~> 0.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
end
Example Usage
Here's how to integrate MapMetrics into your project:
swift
class ViewController: UIViewController, MLNMapViewDelegate {
var mapView: MLNMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView = MLNMapView(
frame: view.bounds,
styleURL: URL(string: "<YOUR_STYLE_URL_HERE>")
)
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)
}
}