Mappedin Logo

Developer

Mappedin Documentation

iOS SDK: Quickstart

iOS SDK: Quickstart

This quickstart guide is written for a new Storyboard application that has been initialized with Cocoapods.

Add dependency to CocoaPods

For more information on how to use Cocoapods, see here.

Mappedin's SDK is available through CocoaPods. You can find the latest version on Github. To install it, add the dependency to your Podfile in your project's root directory:

pod 'MappedIn', '4.0.17'

Make sure platform :ios, '11.0' is set to 11.0 at minimum.

Your Podfile should now have at least the following information with your own app name replacing mappedin-ios-sdk-app:

Podfile
platform :ios, '11.0'
target 'mappedin-ios-sdk-app' do
use_frameworks!
pod 'MappedIn', '4.0.17'
end

In the terminal, run pod install in your project's root directory.

To import the module into the project, add the following line to your ViewController:

import Mappedin

In order for your project to recognize the Pods framework, you must be working from the .xcworkspace file rather than the individual .xcproj file. If you started a new project from scratch in Xcode, you'll need to close it and open the workspace.

Refer to our Github repository to view the sample app created by Mappedin developers to understand how to embed a map into your app.

Display the Venue

Create an MPIMapView instance and Add MPIMapView to View

Now we are ready to initialize an MPIMapView instance mapView in the viewDidLoad() method of your ViewController and add it to the layout:

ViewController.swift
var mapView: MapView?
override func viewDidLoad() {
super.viewDidLoad()
let screenRect = UIScreen.main.bounds
let screenWidth = screenRect.size.width
let screenHeight = screenRect.size.height
// Set up MPIMapView and add to view
mapView = MPIMapView(frame: CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight))
if let mapView = mapView {
self.view.insertSubview(mapView, at: 0)
}
}

Load the Venue

loadVenue is a MPIMapView function that allows you to render the venue in your app by passing in an options object and an optional showVenueOptions object.

The required properties of options object are venue, clientId, clientSecret. To get you started we’ve provided a Mappedin id and ssecret that has access to some demo venues. When you’re ready to start using your own venues with the SDK you will need to (contact a Mappedin representative)[https://www.mappedin.com/contact-us/] to get your own unique id and secret.

PropertyValue
venuemappedin-demo-mall
clientIdSee Here
clientSecretSee Here

You can also pass in showVenueOptions to modify the properties of the map such as the background color, the map that is displayed first and whether all locations are labeled on initialization. Add the following mapView.loadVenue call inside the optional unwrapping of mapView.

ViewController.swift
mapView.loadVenue(options:
MPIOptions.Init(
clientId: "5eab30aa91b055001a68e996",
clientSecret: "RJyRXKcryCMy4erZqqCbuB1NbR66QTGNXVE0x3Pg6oCIlUR1",
venue: "mappedin-demo-mall",
headers: [MPIHeader(name: "name", value: "value")]),
showVenueOptions: MPIOptions.ShowVenue(
labelAllLocationsOnInit: true,
backgroundColor: "#ffffff"
))

Showing cached venue data

showVenue is an alternative method to load the venue without using any API calls to retrieve the data. Instead, the data must be passed into the showVenue method which takes in a data string (which can be retrieved from a file).

Use this sample JSON file to get started with the showVenue method.

Here is an example:

// use showVenue to load venue
if let path = Bundle.main.path(forResource: "mappedin-demo-mall", ofType: "json") {
venueDataString = try? String(contentsOfFile: path)
if let venueDataString = venueDataString {
mapView.showVenue(
venueResponse: venueDataString,
showVenueOptions: MPIOptions.ShowVenue(labelAllLocationsOnInit: true, backgroundColor: "#CDCDCD")
)
}
}

Result

ViewController.swift
import UIKit
import Mappedin
class ViewController: UIViewController {
var mapView: MPIMapView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let screenRect = UIScreen.main.bounds
let screenWidth = screenRect.size.width
let screenHeight = screenRect.size.height
mapView = MPIMapView(frame: CGRect(
x: 0, y: 0, width: screenWidth, height: screenHeight
))
if let mapView = mapView {
self.view.insertSubview(mapView, at: 0)
mapView.loadVenue(options:
MPIOptions.Init(
clientId: "5eab30aa91b055001a68e996",
clientSecret: "RJyRXKcryCMy4erZqqCbuB1NbR66QTGNXVE0x3Pg6oCIlUR1",
venue: "mappedin-demo-mall",
headers: [MPIHeader(name: "name", value: "value")]),
showVenueOptions: MPIOptions.ShowVenue(
labelAllLocationsOnInit: true,
backgroundColor: "#ffffff"
))
}
}
}

You should see something that looks like this:

Search Our Docs

Sign Up

© 2020 Copyright Mappedin, All Rights Reserved. View our Privacy Policy