Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Alirezaa committed Sep 6, 2022
1 parent 046b82d commit a8d462f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 6 deletions.
77 changes: 75 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
# MapirMapKit
# Map.ir Map Kit

A description of this package.
Map.ir Map Kit is an interactive map based on Mapbox framework, providing Map.ir tiles.

## Features
- Supports Swift and Objective-C
- Customizable map and gestures.
- Support for Interface builder.
- **All with Map.ir vector tiles.**


## Example

To see the example application, first clone the project using `git clone https://github.com/map-ir/mapir-ios-maps-sdk` in terminal.
Open `SampleApp/SampleApp.xcodeproj`. Build and run `SampleApp` target.

You need to put your Map.ir API key in a file at your home directory named `.mapir` or just enter it in SampleApp's `AppDelegate.swift` in `application(_:didFinishLaunchingWithOptions:)` using the following code:

```swift
MapirAccountManager.shared.set(apiKey: "eyJ0eXAiO...")
```

## Installation

### Swift Package Manager

> **Note**
> Since Map.ir maps SDK is based on Mapbox's SDK, you need to follow [Mapbox's Instruction](https://docs.mapbox.com/ios/maps/guides/install/#configure-credentials) to be able to install the SDKs.
Map.ir Map Kit is available through [Swift Package Manager](https://www.swift.org/package-manager/). To install
it, simply add the following line to your dependencies of your Package.swift file:

```swift
.package(name: "MapirMapKit", url: "https://github.com/map-ir/mapir-ios-maps-sdk.git", from: "2.0.0"),
```

Or, if you are using Xcode, Click on "File > Add Packages" enter the following URL in the search box.
then set the version to `from: 4.0.0`.

```
https://github.com/map-ir/mapir-ios-maps-sdk.git
```

## Usage
This SDK is compatible with both Swift and Objective-C programming languages, using iOS 9.0 or newer.

first import Map.ir MapKit.

```swift
import MapirMapKit
```

Then use initializers for of `MapirMapView` to create an instance of it. `MapirMapView` is the subclass of [`MapView`](https://docs.mapbox.com/ios/maps/api/10.7.0/Classes/MapView.html#/MapView) with Map.ir tiles.

```swift
struct MapirAttributionURLOpener: AttributionURLOpener {
func openAttributionURL(_ url: URL) {}
}

class ViewController: UIViewController {
var mapView: MapirMapView!

override func viewDidLoad() {
super.viewDidLoad()
mapView = MapirMapView(frame: view.bounds, mapInitOptions: .mapirCompatible(), urlOpener: MapirAttributionURLOpener())
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.view.addSubview(mapView)
}

...
}
```

## Contributing

Contributions are very welcome. 🙌
2 changes: 1 addition & 1 deletion SampleApp/SampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -o pipefail\n\nMAPIR_API_KEY_FILE=~/.mapir\n\nif [ ! -f \"$MAPIR_API_KEY_FILE\" ]; then\n echo \"Map.ir API key not found. API key needs to be located in a text file at ~/.mapir\"\n exit 1\nfi\n\nMAPIR_API_KEY=$(cat ~/.mapir)\n\nplutil -insert MapirAPIKey -string $MAPIR_API_KEY ${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\n";
shellScript = "MAPIR_API_KEY_FILE=~/.mapir\n\nif [ ! -f \"$MAPIR_API_KEY_FILE\" ]; then\n echo \"Map.ir API key not found. API key needs to be located in a text file at ~/.mapir or pass it in `MapirAccountManager.shared.set(apiKey:)`\"\n exit 0\nfi\n\nMAPIR_API_KEY=$(cat ~/.mapir)\n\nplutil -insert MapirAPIKey -string $MAPIR_API_KEY ${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
8 changes: 5 additions & 3 deletions SampleApp/SampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import MapirMapKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
guard let apiKey = Bundle.main.object(forInfoDictionaryKey: "MapirAPIKey") as? String else {
fatalError(#"Unable to locate key named "MapirAPIKey" in Info.plist file."#)
if let apiKey = Bundle.main.object(forInfoDictionaryKey: "MapirAPIKey") as? String {
MapirAccountManager.shared.set(apiKey: apiKey)
} else {
print(#"You need to specify a Map.ir API key in the bottom function. If you don't have one, please checkout "https://help-mapir.imber.ir/fa/post/60963c70c156fb9c4d587a1b""#)
// MapirAccountManager.shared.set(apiKey: <YOUR_API_KEY>)
}

MapirAccountManager.shared.set(apiKey: apiKey)
MapirMapKit.registerHTTPService()

return true
Expand Down

0 comments on commit a8d462f

Please sign in to comment.