Instance Method

init

Initialize a mapkit object by providing an authorization callback and language.

Declaration

void init (MapKitInitOptions options);

Parameters

options

MapKit JS initialization options.

Discussion

Once you have completed your one-time Setting Up MapKit JS on the Apple Developer Website, you are ready to initialize MapKit JS.

If you are using a server to deliver new tokens to MapKit JS, make an asynchronous request to your server here and call the done() function with the result.

mapkit.init({
    authorizationCallback: function(done) {
        fetch("/gettoken")
            .then(res => res.text())
            .then(done);
    },
    language: "es"
});

Otherwise, you can simply pass a pre-generated token string.

mapkit.init({
    authorizationCallback: function(done) {
        done("your-token-string");
    },
    language: "es"
});

The init call can be made before the content of your page has fully loaded (e.g., before the window's “load” event has fired).

That's all that's needed to start using the MapKit JS framework. MapKit JS is standalone with no dependencies on other JavaScript libraries. At the same time, it doesn't preclude you from using other JavaScript libraries and frameworks in your codebase.

Signing your Authorization Token with JWT

Visit http://jwt.io for a list of recommended modules for most development languages. You will need the following details when configuring JWT to properly generate a signed authorization token:

All of the properties below are required for MapKit JS to successfully load

payload object

Property

Value

iat

Time issues in seconds since unix epoch

exp

Expiry time in seconds since unix epoch

iss

Your Apple Developer Team ID

origin

A domain restriction which should match the Origin header passed by a browser. (recommended)

config.header object

Property

Value

alg

"ES256"

typ

"JWT"

kid

Your Key ID

The code for signing a JWT token can be run server-side, and exposed as a web-service to your front-end. It can also be run on a development machine to generate a long-lived token to be checked directly into source-code. Libraries for signing JWT tokens can be found at jwt.io for most programming languages.

See Also

Initialization

Handling Initialization Events

Handle events triggered when mapkit is initialized.

MapKitInitOptions

Initialization options you set when creating a mapkit object.

Beta
addEventListener

Adds listener as a callback for an event of type.

Beta
removeEventListener

Removes listener as a callback for an event of type.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software