If you’d like your view to be positioned above the coordinate instead, you can use Annotation’s anchor parameter. This SwiftUI view will be displayed on the map centered right on the parking coordinate. Here, I’m using ZStack to compose some shapes and an image. I want to display a custom SwiftUI view for the parking spot, so I’ll use an Annotation to mark it. For now, all you really need to know is that you can use the content builder closure to add all kinds of content to the map. You’ll learn more about these a bit later. The content builder can be used to present overlay content as well. Instead of Marker’s balloon, Annotation displays a SwiftUI View. Like Marker, Annotation is used to display content at a specific coordinate. You’ll find Markers used in the Maps app and across the platform, including in a wide variety of apps you can find on the App Store. The balloon shape might look familiar to you. So what’s a Marker? Are there other types of content that I can present using the content builder? Markers are used to display content at a specific coordinate on the map. Check out how the map has automatically framed our content by zooming in to show the Marker. Cool! If you’re familiar with SwiftUI, adding a Marker to the map feels a lot like adding a View to a List. So, let’s park the car and start walking! I’ll use a MapContentBuilder closure to add a marker to the map. You’ll learn about using Marker and Annotation to display content at a specific coordinate on the map. I’ll mark the spot right above the ramps that vehicles use to access the garage, near the elevator we’ll ride up to start walking. The first thing I’ll do is add some content to the map to mark the parking garage. Boston Common is a beautiful park right in the middle of everything, and it’ll make a fantastic starting point for our walking tour. I’ve heard it said that there’s a particular place you should "pahk" your "cah" near Boston, but I like the parking garage right underneath the Common. Nice! I have an interactive map with just one line of code! My family will start the day by driving into the city and parking so we can walk around. Let’s get right into it! I’ll start with a brand-new SwiftUI project. I’ll add some controls to the map, including a user location button, so that I can figure out where I am. I’ll show you how to display satellite and flyover imagery as well. I’ll add another dimension to the map by enabling realistic elevation. I’ll use the map to display different locations and regions. I’ll add an overlay that shows a driving route to the beach. I’ll integrate Look Around to explore some places we might want to visit. I’ll enable selection so that I can tap on each marker to learn more about that place. I’ll use annotations to mark places on the map. I’ll build an app to help us plan the day. The weather is looking perfect, too, so we’ll head out to the beach in the afternoon and feel the sand between our toes. We’ll walk through the city in the morning and see the sights, we’ll have lunch in the historic North End, and probably grab a cannoli for dessert. My family is heading back home to New England this weekend, and we’ll spend Saturday exploring the beautiful city of Boston. I’ll walk you through every step and we’ll be done before the end of this session. To show you how easy it is, I’ll build a fully functional trip planner from scratch. We think you’re going to love using MapKit for SwiftUI to create powerful mapping experiences for your users. With our greatly expanded SwiftUI API, it’s easier than ever to integrate Maps into your apps across all platforms. I’m an engineer on the MapKit team and I’m excited to introduce you to MapKit for SwiftUI.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |