Step 1.

when old apple map api token expired, 

you will need create a new api token, 

and replace it in file

 

 

 

Step 2.

sample : 

     use server-side endpoint to get generate a short-term token each time to avoid hard code static token in js file. 

     https://rajeshlv.medium.com/using-apple-mapkit-js-for-web-applications-15c4cff0e2

 

 

     only use long-term static token( no server side token setup)

     https://www.createwithswift.com/using-mapkit-js-to-embed-apple-maps-in-websites/

 

 

 

 

 

 

1) long-term static token required in script tag when load apple mapkit, 

 

     layout.pug 

           script(type='module' src='https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.core.js' crossorigin async data-callback="initMap" data-libraries="services,full-map,overlays,annotations,geojson,user-location" data-initial-token= apple_token ) 

 

           'data-initial-token' attribute must use 'apple_token'

            this is static apple token stored in '.env' file. so far I set it expire in 1 year, which is 2024/2/6

 

            when long term static token expired, I will go to this page to generate a new one. 

            static apple token is generated on apple developer home page, use create token page

                https://maps.developer.apple.com/token-maker

 

                domain restriction should be 'localhost, transparentgov.net', without this, I will get warning '[MapKit] Authorization token without origin restriction is not recommended in production environments.'

 

 

 

2) short-term signed apple token, is required, without this, I will get warning "mapkit need verify token later"

 

     this is get token url, 

            "http://localhost:3000/services/jwt"

            "https://transparentgov.net:3200/services/jwt"

 

      I create endpoint on server, these 2 url should return a token

           in js, use  "await setupMapKitJs();"

           for signed token.

 

 

 

warning: 

            when loading apple mapkit,  I found lots of Error message "DevTools failed to load SourceMap: Could not load content for ......

            https://stackoverflow.com/questions/61339968/error-message-devtools-failed-to-load-sourcemap-could-not-load-content-for-chr

            This is because of chrome, developer tool, I can turn off warning by 

            Go to the developer tools (F12 in the browser), then select the three dots in the upper right corner, and go to Settings.

            Then, look for Sources, and disable the options:

            "Enable JavaScript source maps"

            "Enable CSS source maps"

 

 

 

Step 3.

https://maps.developer.apple.com/token-maker

 

 

Step 4.

 

 

 

 

Step 5.

 

 

 

Step 6.

 

 

 

Step 7.

 

 

 

Step 8.

copy paste new apple token here.  

 

 

 

Step 9.

 

 

 

 

 

 

 

 

Step 10.

 

 

 

 

Step 11.

 

 

 

 

Step 12.

 

 

 

 

Step 13.

 

 

 

 

 

Step 14.

 

 

 

 

Step 15.

 

 

 

 

 

Step 16.

 

 

Step 17.

 

Step 18.

 

Step 19.

 

Step 20.

 

 

by

Please log in or register