How to initialize a MapView() with TomTom SDK in Xcode?

88 Views Asked by At

I have installed and imported TomTomSDKMapDisplay into my Xcode project and am trying to display a map on a view. Following the TomTom Developer instructions, I am trying to assign my api key. Here is the link to the instructions I have been following (this is my first time attempting to make use of APIs in Xcode): https://developer.tomtom.com/ios/maps/documentation/guides/map-display/quickstart#getting-the-map

However, when MapsDisplayService.apiKey = "ThisIsKey" is placed in var body: some View {, the error

Type '()' cannot conform to 'View'

is given. Where then am I supposed to write this line? Below is a screen shot of the code.

enter image description here

1

There are 1 best solutions below

0
On

According to the documentation, if you want to set the API key, you need to do it before a MapView can be used. As an example, this can be done in the didFinishLaunchingWithOptions delegate method.

Then in your View class, you can instantiate the MapView.

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 
   MapsDisplayService.apiKey = “MAP_KEY” 
   […] 
   return true
}