I am using an unrestricted api key for Google Maps SDK for iOS with my iOS Xcode project after having created a new key and deleting the old key, but my request is denied. It worked before when I used the first key.
Here is the error message:
[error_message: This API project is not authorized to use this API., status: REQUEST_DENIED, routes: <__NSArrayM 0x60000097f5d0>(
)
Here is my code in AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GMSServices.provideAPIKey("***")
GMSPlacesClient.provideAPIKey("***")
}
Here is my code where I run the request:
let directionsURLString = "https://maps.googleapis.com/maps/api/directions/json?origin=1%20Cuntry%20Club%20Ln,%20Texarkana,%20AR&destination=1%20Cuntry%20Club%20Ln,%20Texarkana,%20AR&waypoints=optimize:true%7C921%20Orleans%20St,%20Texarkana,%20AR%7C2510%20E.%2011th%20St.,%20Texarkana,%20AR%2071846%7C4125%20Lynn%20Dr,%20Texarkana,%20TX%7C6002%20Yorktown%20Pl,%20Texarkana,%20TX%7C7007%20Stonewall%20Dr,%20Texarkana,%20TX%7C4009%20Constitution%20Dr,%20Texarkana,%20TX%7C413%20Dundee%20Rd,%20Texarkana,%20AR%7C2219%20Hazel%20St,%20Texarkana,%20TX%7C414%20Central%20Ave,%20Wake%20Village,%20TX&mode=driving&key=***"
let directionsURL = URL(string: directionsURLString)!
DispatchQueue.main.async {
do {
let directionsData = try Data(contentsOf: directionsURL)
let dictionary: Dictionary<NSObject, AnyObject> = try JSONSerialization.jsonObject(with: directionsData, options: JSONSerialization.ReadingOptions.mutableContainers) as! Dictionary<NSObject, AnyObject>
print(dictionary)
let status = dictionary["status" as NSObject] as! String
print("status=" + status)
} catch {
print(error)
}
}