2
2

【SwiftUI】MapStyleについて調べた(iOS17)

Posted at

はじめに

本記事のベースコード

import SwiftUI
import MapKit

struct ContentView: View {
    // 東京駅の座標
    @State private var position: MapCameraPosition = .region(.init(
        center: .init(latitude: 35.681236, longitude: 139.767125),
        span: .init(latitudeDelta: 0.1, longitudeDelta: 0.1)
    ))

    var body: some View {
        Map(position: $position)
            .mapStyle( /* ここにスタイルを指定 */ )
    }
}

スタイル

.standard .imagery .hybrid
simulator_screenshot_CEE0EE75-286D-4EDA-B830-91D6230C090B.png Simulator Screenshot - iPhone 15 - 2023-11-27 at 21.21.53.png simulator_screenshot_70F2695E-C573-41AD-B433-331CBD552975.png

.standard

.mapStyle(.standard(elevation: , emphasis: , pointsOfInterest:, showsTraffic: ))
  • elevation: マップの標高のレンダリング方法を指定する
  • emphasis: マップの特徴を強調する方法を制御する
  • pointsOfInterest: 地図上に表示されるPointOfInterestCategoriesを指定する
  • showsTraffic: マップにトラフィックを表示するかどうかを指定する

.imagery

.mapStyle(.imagery(elevation: ))
  • elevation: マップの標高のレンダリング方法を指定する

.hybrid

.mapStyle(.hybrid(elevation: , pointsOfInterest: , showsTraffic: ))
  • elevation: マップの標高のレンダリング方法を指定する
  • pointsOfInterest: 地図上に表示されるPointOfInterestCategoriesを指定する
  • showsTraffic: マップにトラフィックを表示するかどうかを指定する

elevationについて

standardだと違いがわかりませんでした
imageryだとこんな感じの違いがある

flat realistic
simulator_screenshot_823AF141-D039-4286-9D44-B4DFCC3B87CC.png simulator_screenshot_BD5F6441-DCF1-4FB0-99BD-EC8D6EB26097.png

emphasisについて

ちょっと色が薄くなった

automatic muted
simulator_screenshot_0A1C567D-A0A1-45E7-AEEC-DB266BF125FF.png simulator_screenshot_EB00EB31-BE11-42BF-A3A7-C704EF77CEC4.png

pointsOfInterestについて

建物のマークが消えてますね

all excludingAll
simulator_screenshot_0A1C567D-A0A1-45E7-AEEC-DB266BF125FF.png simulator_screenshot_19BBCE0D-406C-4725-99E9-0FD2BF40E114.png

showsTrafficについて

デフォルトはfalseです

false true
simulator_screenshot_4755303D-6421-4451-91C2-390368619786.png simulator_screenshot_14F31306-6AB6-429D-9FDA-A3F39C55BFB8.png

おわり

iOS17からMapKitがめっちゃ便利になったので活用してアプリ作ってみたいです

公式ドキュメント

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2