https://developer.apple.com/documentation/applemapsserverapi/creating-and-using-tokens-with-maps-server-api
This doesn't really say what to do with .p8 private key. I know I am a noob but I really don't understand Apple Doc at all. There is no example or anything like that.
const appleMapKit = await fetch("https://maps-api.apple.com/v1/token", {
headers: {
Authorization: `Bearer ${server_api_token}`,
},
});
This is what I did but because I created the token on website, server_api_token only lasts 7 days.
So, I tried to use Profile - Key to replace that. I have .p8 file and how can I use this to create the token for the server api?
Apple Maps Server API
RSS for tagIncrease performance, lower data usage, and improve battery life across platforms for a variety of Apple Maps features.
Posts under Apple Maps Server API tag
13 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I'm trying to use the new Apple Maps Server API. As far as I can tell I have set up the token correctly, but my web request is still returning 401 unauthorized.
The following is my code in TypeScript:
import * as jwt from 'jsonwebtoken';
const JWT_SECRET = "-----BEGIN PRIVATE KEY-----\n" +
"MIGTAgEAMBMGBy..............................\n" +
"..............................................................\n" +
"..............................................................\n" +
"-----END PRIVATE KEY-----";
const header = {
alg: "ES256",
kid: "26DYPK65ZK",
typ: "jwt"
}
// Example payload data
const payload = {
"iss": "7F3PBYWYMS",
"iat": Date.now(),
"exp": Date.now() + (1000 * 30 * 60),
};
export async function getRestaurants() {
let token = jwt.sign(payload, JWT_SECRET, { algorithm: 'ES256', header: header});
const response = await fetch('https://maps-api.apple.com/v1/token (https://maps-api.apple.com/v1/token)', {
method: 'GET',
headers: {
'Authorization': "Bearer " + token
},
});
console.log(response);
}
What am I doing incorrectly here?
I upgraded to IOS 18 earlier this week. When I used Apple Maps on Carplay last night, Siri would only say that it was looking for directions. The destination never came through CarPlay. It should have been an easy one, as I was taking someone to the airport to fly to Atlanta.
Hello there
I recently upgraded my iPhone 15 to ios 18 public beta which led to battery drain issues even during overnight around 10-15%. Besides this I am facing heating while just clicking photos in broad daylight
at just 28-32 degree tem. So any solutions to my issues…
Previously (and still, according to the documentation) building a Map Snapshot URL required building the URL with all its parameters, and then signing it using your private key.
However, the URL created via the "Create a map" tool simply appends the pre-generated token on the end of the URL. And if I build a URL and do the same thing - append the token, but do not create a signature - the snapshot is generated correctly. (Omitting the token leads to a "not authenticated" message).
Is this a new, easier way to generate snapshots?
Is MultiPolygon overlay support going to be integrated with SwiftUI?
I have made a post on here previously without a reply :(
Any suggestions on how to display multi-polygons within MapKit for SwiftUI(https://developer.apple.com/documentation/mapkit/mappolygon)?
At the moment it is not supported and only supported by MapKit for UIKit(https://developer.apple.com/documentation/mapkit/mkmultipolygon).
Edit: The issue was resolved. It's back up.
I was streaming the new MapKit Places video, and it suddenly stopped. It's now missing from the Developer app and website. Is this intentional?
Hello,
I'm truing to use Maps Server API. I have:
Created Maps Identifier and a Private Key
Used token maker to create a JWT token. I also tried creating JWT token manually.
After generating a JWT token I used Maps Server API Playground with my JWT and I can successfully use Maps Server API.
The problem is that when I try to use my JWT in either JS code, Postman or curl request, I get "Invalid Token" error. Which is very strange, because I doubled checked everything dozen of times and JWT works in Apple's playground tool.
Here's a request example:
curl -si -H"Authorization: Bearer <jwt token>" "https://maps-api.apple.com/v1/geocode?q=Apple%20Park%2C%20Cupertino%2C%20CA"
My token is valid for 1 year
When generating JWT token I left "Domain restriction" field empty.
I am trying to migrate some of my mapkit code to the Map Server API. My JWT is fine and I can use that within the API Playground just fine. However, when I try to implement a test using PHP and cURL to get my Map token, I receive a 401 Not Authorized Error. My code is below:
<?php
$URL="https://maps-api.apple.com/v1/token";
$accesstoken = "<MY TOKEN HERE>";
$authorization = 'Authorization: Bearer'.$accesstoken;
$headers = [];
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, [$authorization]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADERFUNCTION,
function($curl, $header) use (&$headers)
{
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) // ignore invalid headers
return $len;
$headers[strtolower(trim($header[0]))][] = trim($header[1]);
return $len;
}
);
$result=curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
curl_close ($ch);
print_r($headers);
echo($result);
echo($status_code);
?>
Now the exact response that I am receiving is:
Array ( [date] => Array ( [0] => Thu, 18 Apr 2024 18:32:15 GMT ) [content-type] => Array ( [0] => application/json;charset=utf8 ) [content-length] => Array ( [0] => 51 ) [connection] => Array ( [0] => keep-alive ) [cache-control] => Array ( [0] => max-age=0 ) [x-rid] => Array ( [0] => c9507281-bc32-46ac-be3b-dc59e97e7fed ) [strict-transport-security] => Array ( [0] => max-age=31536000; includeSubDomains; ) )
{"error":{"message":"Not Authorized","details":[]}}
401
Any help getting this to work would be appreciated.
I need to fetch nearby places within a 3 km radius using the Apple Maps API
I am making an app like Taxi Driving, where users can add location and driver to that location. The problems I am facing are below:
Drawing a route on MKMap - I get the route polyline and I render that on the map. Now what should happen as I am driving, the drove part of the polyline should get removed or may be turned grey, non-drove part should be blue. Currently, I am only able to do this by again getting a route from my current location and re-drawing on the map which is not a good thing I suppose.
Show driving instructions - I need to show step-by-step instructions which I get in the MKStep under the MKRoute object. But I don't get the icons that I can show such as Turn Right or Turn left the only thing I have is plain text. I need an icon along with it and also how to identify once I have crossed the step and show the next step as my next instruction.
These two are the major problems I am facing and I need to do this with Apple native map view itself so no third-party integration I want.
Regardless of how much information is provided to the Maps searchAutoComplete API, the response field structuredAddress is always null. This means I have to call the completionUrl afterwards to get a structured address. This consumes our quota and causes unnecessary Maps traffic.
Example request, autocompleting "450 Post St, San Francisco":
https://maps-api.apple.com/v1/searchAutocomplete?
q=450%20Post%20St%2C%20San%20Francisco
&resultTypeFilter=Address
&limitToCountries=US
&lang=en-US
responds 2 results with the actual address found, but each having only these fields:
- completionUrl
- displayLines
- location
Example:
{
"results": [
{
"completionUrl": "/v1/search?q=450%20Post%20St%20San%20Francisco%2C%20CA%2C%20United%20States&metadata=Ch8KCzQ1MCBQb3N0IFN0EgQIABADEgQIBBAEEgQICRACEjQKIFNhbiBGcmFuY2lzY28sIENBLCBVbml0ZWQgU3RhdGVzEgQIGhACEgQIABADEgQIBBAJGAIyRgoSCQAAAEDg5EJAEQAAAOA9ml7AEM6h0aK1wfKqciA5KQAAAAAAAHlAgvEEAzQ1MIjxBDGa8QQCVVOg8QQAsvEEALrxBABiHAoaNDUwIFBvc3QgU3QsIFNhbiBGcmFuY2lzY2%2BC8QQaNDUwIFBvc3QgU3QsIFNhbiBGcmFuY2lzY2%2BI8QQA2vEEFgkAAABAEf3IQBkAAAAAAAAAACABKAPq8QQAkPIEAQ%3D%3D",
"displayLines": [
"450 Post St",
"San Francisco, CA, United States"
],
"location": {
"latitude": 37.78809356689453,
"longitude": -122.41002655029297
}
},
{
"completionUrl": "/v1/search?q=450%20Post%20St%20Napa%2C%20CA%2C%20United%20States&metadata=****",
"displayLines": [
"450 Post St",
"Napa, CA, United States"
],
"location": {
"latitude": 38.30093002319336,
"longitude": -122.27799224853516
}
}
]
}
Anyone figured this out? Seems buggy to me.
Hi, based on https://developer.apple.com/help/account/configure-app-capabilities/create-a-maps-identifier-and-private-key described, I need to create an Identifier before I can create JWT for MapKit JS. However, I cannot find Maps Ids checkbox when I attempt to set up first MapKit JS access.