{"id":425,"date":"2025-05-29T11:21:24","date_gmt":"2025-06-05T03:31:24","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=425"},"modified":"2025-06-05T11:21:24","modified_gmt":"2025-06-05T03:31:24","slug":"swift-google-map-%e6%a8%99%e8%a8%98-%e5%ae%9a%e4%bd%8d-%e5%a4%a7%e9%a0%ad%e9%87%9d","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/swift-google-map-%e6%a8%99%e8%a8%98-%e5%ae%9a%e4%bd%8d-%e5%a4%a7%e9%a0%ad%e9%87%9d\/","title":{"rendered":"2025 \u6700\u65b0 Swift \u7a0b\u5f0f\u6559\u5b78\uff1a\u4f7f\u7528 Google Maps SDK \u6a19\u8a18\u8207\u5b9a\u4f4d"},"content":{"rendered":"<h3>\u7c21\u8981<\/h3>\n<p>Google Maps \u662f\u4e00\u500b\u5ee3\u6cdb\u4f7f\u7528\u7684\u5730\u5716\u670d\u52d9\uff0c\u7121\u8ad6\u662f\u5728\u61c9\u7528\u7a0b\u5f0f\u6216\u662f\u7db2\u9801\u4e0a\uff0c\u7686\u80fd\u65b9\u4fbf\u5730\u67e5\u8a62\u5730\u9ede\u3001\u898f\u5283\u8def\u7dda\u4ee5\u53ca\u7372\u53d6\u516c\u8eca\u8cc7\u8a0a\uff0c\u751a\u81f3\u80fd\u540c\u6b65\u96fb\u8166\u8207\u624b\u6a5f\u4e0a\u7684\u7d00\u9304\u3002\u76f8\u8f03\u65bc Apple Maps\uff0cGoogle Maps \u5728\u529f\u80fd\u4e0a\u986f\u5f97\u66f4\u70ba\u5b8c\u6574\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 Google Maps SDK \u4f86\u5be6\u73fe\u4f4d\u7f6e\u6a19\u8a18\u8207\u5b9a\u4f4d\u529f\u80fd\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/ithelp.ithome.com.tw\/upload\/images\/20191005\/20112271rO6xDkzZPs.png\" alt=\"Google Maps SDK \u754c\u9762\" title=\"\"><\/p>\n<h3>\u91d1\u9470\u7533\u8acb<\/h3>\n<p>\u4f7f\u7528 Google Maps SDK \u524d\uff0c\u9996\u5148\u9700\u8981\u7533\u8acb\u4e00\u7d44\u91d1\u9470\u3002\u8acb\u6ce8\u610f\uff0cGoogle Maps API \u4e0d\u662f\u5b8c\u5168\u514d\u8cbb\u7684\uff0c\u8d85\u904e\u4e00\u5b9a\u6d41\u91cf\u5f8c\u6703\u6536\u53d6\u8cbb\u7528\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/JrkLxnE.gif\" alt=\"Google Maps API \u91d1\u9470\u7533\u8acb\u6b65\u9a5f\" title=\"\"><\/p>\n<p>\u8acb\u8a2a\u554f\u4ee5\u4e0b\u9023\u7d50\u4ee5\u7533\u8acb\u91d1\u9470\uff1a<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/cloud.google.com\/maps-platform\/maps\/\" target=\"_blank\" rel=\"noopener\">Google API<\/a><\/p>\n<h4>Step 1 &#8211; \u9ede\u64ca\u958b\u59cb\u4f7f\u7528<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/ithelp.ithome.com.tw\/upload\/images\/20191005\/20112271AovEWI4XHw.png\" alt=\"\u958b\u59cb\u4f7f\u7528 Google Maps API\" title=\"\"><\/p>\n<h4>Step 2 &#8211; \u9ede\u9078\u60f3\u4f7f\u7528\u7684\u529f\u80fd<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/ithelp.ithome.com.tw\/upload\/images\/20191005\/20112271HzZ5CPkabM.png\" alt=\"\u9078\u64c7\u529f\u80fd\" title=\"\"><\/p>\n<h4>Step 3 &#8211; \u65b0\u589e\u5c08\u6848<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/ithelp.ithome.com.tw\/upload\/images\/20191005\/20112271YiOIpVJx4q.png\" alt=\"\u65b0\u589e\u5c08\u6848\" title=\"\"><\/p>\n<p>\u63a5\u4e0b\u4f86\u8acb\u6301\u7e8c\u6309\u4e0b\u4e00\u6b65\u3002<\/p>\n<h4>Step 4 &#8211; \u53d6\u5f97\u91d1\u9470<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/ithelp.ithome.com.tw\/upload\/images\/20191005\/20112271gVJ68pX5si.png\" alt=\"\u53d6\u5f97\u91d1\u9470\" title=\"\"><\/p>\n<blockquote><p>\n  <code>\u91d1\u9470\u975e\u5e38\u91cd\u8981\uff0c\u8acb\u59a5\u5584\u4fdd\u7ba1\u3002<\/code>\n<\/p><\/blockquote>\n<h3>\u74b0\u5883\u5b89\u88dd<\/h3>\n<p>\u5982\u679c\u4f60\u5c1a\u672a\u5b89\u88dd Cocoapods\uff0c\u8acb\u6253\u958b mac \u7684\u7d42\u7aef\u6a5f\uff0c\u5207\u63db\u5230\u4f60\u7684 iOS \u5c08\u6848\u8cc7\u6599\u593e\uff0c\u4e26\u57f7\u884c\u4ee5\u4e0b\u6307\u4ee4\uff1a<\/p>\n<pre><code class=\"line-numbers\">pod init\n<\/code><\/pre>\n<p>\u9019\u6703\u5728\u8cc7\u6599\u593e\u5167\u751f\u6210\u4e00\u500b Podfile\u3002\u8acb\u6253\u958b\u8a72\u6587\u4ef6\uff0c\u4e26\u65b0\u589e Google Maps \u7684 SDK\uff1a<\/p>\n<pre><code class=\"line-numbers\">pod 'GoogleMaps'\npod 'GooglePlaces'  \n<\/code><\/pre>\n<p>\u5132\u5b58\u6587\u4ef6\u5f8c\uff0c\u8fd4\u56de\u7d42\u7aef\u6a5f\u4e26\u904b\u884c\u4ee5\u4e0b\u6307\u4ee4\u5b89\u88dd\uff1a<\/p>\n<pre><code class=\"line-numbers\">pod install\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/ithelp.ithome.com.tw\/upload\/images\/20191005\/20112271L6rJH1Fakt.png\" alt=\"\u5b89\u88dd Google Maps SDK\" title=\"\"><\/p>\n<p>\u5b8c\u6210\u5f8c\uff0c\u8acb\u6253\u958b\u65b0\u751f\u6210\u7684 `.xcworkspace` \u6a94\u6848\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/ithelp.ithome.com.tw\/upload\/images\/20191005\/20112271a2cmsKaJM6.png\" alt=\"\u6253\u958b .xcworkspace \u6a94\u6848\" title=\"\"><\/p>\n<p>\u5728 `AppDelegate` \u4e2d\u6dfb\u52a0\u4f60\u525b\u525b\u7533\u8acb\u7684\u91d1\u9470\uff0c\u900f\u904e `GMSServices.provideAPIKey` \u65b9\u6cd5\u4f7f\u6240\u6709 class \u53ef\u4ee5\u4f7f\u7528 Google Maps SDK\u3002<\/p>\n<pre><code class=\"language-swift line-numbers\">import UIKit\nimport GoogleMaps\n\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n    let apiKey = \"YOUR_API_KEY\" \/\/ \u66ff\u63db\u70ba\u4f60\u7684\u91d1\u9470\n    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {\n        GMSServices.provideAPIKey(apiKey)\n        return true\n    }\n}\n<\/code><\/pre>\n<h3>\u65b0\u589e\u5730\u5716\u8996\u5716<\/h3>\n<p>\u4f7f\u7528 `GMSMapView` \u4f86\u65b0\u589e\u5730\u5716\u8996\u5716\uff0c\u4ee5\u4e0b\u662f\u793a\u7bc4\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let mapView = GMSMapView()\nmapView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)\nself.view.addSubview(mapView)\n<\/code><\/pre>\n<h3>\u8a2d\u7f6e\u5730\u5716\u7684\u76f8\u6a5f\u4f4d\u7f6e<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528 `GMSCameraPosition` \u4f86\u8a2d\u5b9a\u5730\u5716\u7684\u521d\u59cb\u4f4d\u7f6e\uff0c\u4ee5\u4e0b\u662f\u793a\u7bc4\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let camera = GMSCameraPosition.camera(withLatitude: 25.034012, longitude: 121.564461, zoom: 15.0) \/\/ \u8a2d\u5b9a\u70ba\u53f0\u5317101\u4f4d\u7f6e\nmapView.camera = camera\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/ithelp.ithome.com.tw\/upload\/images\/20191005\/20112271x1P2MDXmbH.png\" alt=\"\u8a2d\u5b9a\u76f8\u6a5f\u4f4d\u7f6e\" title=\"\"><\/p>\n<h3>\u65b0\u589e\u6a19\u8a18\uff08\u5927\u982d\u91dd\uff09<\/h3>\n<p>\u4f7f\u7528 `GMSMarker` \u4f86\u65b0\u589e\u6a19\u8a18\uff0c\u4e26\u8a2d\u7f6e\u6a19\u984c\u8207\u526f\u6a19\u984c\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let marker = GMSMarker()\nmarker.position = CLLocationCoordinate2DMake(25.034012, 121.563461)\nmarker.map = mapView\nmarker.title = \"\u6a19\u984c1\"\nmarker.snippet = \"\u526f\u6a19\u984c1\"\n\nlet marker2 = GMSMarker()\nmarker2.position = CLLocationCoordinate2DMake(25.034012, 121.566461)\nmarker2.map = mapView\nmarker2.title = \"\u6a19\u984c2\"\nmarker2.snippet = \"\u526f\u6a19\u984c2\"\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/ithelp.ithome.com.tw\/upload\/images\/20191005\/20112271o4ixLMwRU6.png\" alt=\"\u65b0\u589e\u6a19\u8a18\" title=\"\"><\/p>\n<blockquote><p>\n  \u5b8c\u6210\uff01\u4f60\u73fe\u5728\u5df2\u7d93\u6210\u529f\u6574\u5408 Google Maps SDK \u81f3\u4f60\u7684 Swift \u5c08\u6848\u3002\n<\/p><\/blockquote>\n<h3>\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff08Q&#038;A\uff09<\/h3>\n<h4>Q1: \u5982\u4f55\u7372\u53d6 Google Maps API \u91d1\u9470\uff1f<\/h4>\n<p>A1: \u8acb\u8a2a\u554f [Google Cloud Console](https:\/\/console.cloud.google.com\/)\uff0c\u8a3b\u518a\u4e26\u5275\u5efa\u5c08\u6848\u5f8c\uff0c\u6309\u7167\u6b65\u9a5f\u7533\u8acb API \u91d1\u9470\u3002<\/p>\n<h4>Q2: \u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 Google Maps SDK\uff1f<\/h4>\n<p>A2: \u9700\u8981\u5148\u5b89\u88dd Cocoapods\uff0c\u7136\u5f8c\u5728 Podfile \u4e2d\u6dfb\u52a0 `pod &#8216;GoogleMaps&#8217;` \u548c `pod &#8216;GooglePlaces&#8217;`\uff0c\u63a5\u8457\u5b89\u88dd\u4e26\u5728 `AppDelegate` \u4e2d\u63d0\u4f9b API \u91d1\u9470\u3002<\/p>\n<h4>Q3: Google Maps API \u662f\u5426\u6536\u8cbb\uff1f<\/h4>\n<p>A3: \u662f\u7684\uff0cGoogle Maps API \u63d0\u4f9b\u4e00\u5b9a\u7684\u514d\u8cbb\u914d\u984d\uff0c\u8d85\u904e\u5f8c\u6703\u6839\u64da\u4f7f\u7528\u91cf\u6536\u8cbb\uff0c\u5efa\u8b70\u67e5\u770b\u5b98\u65b9\u6587\u4ef6\u4e86\u89e3\u8a73\u7d30\u8cc7\u8a0a\u3002<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73fe\u5728`Google Map`\u61c9\u8a72\u662f\u5f88\u591a\u4eba\u90fd\u6703\u4f7f\u7528<br \/>\n\u4e0d\u7ba1\u662f`APP`\u6216\u662f`Web`\u90fd\u5f88\u597d\u7528<br \/>\n\u67e5\u8a62\u5730\u9ede\u898f\u5283\u8def\u7dda<br \/>\n`\u516c\u8eca\u8cc7\u8a0a` \u8981\u642d\u5e7e\u865f\u8eca<br \/>\n\u5176\u5be6\u4e0a\u9762\u90fd\u6709\u5448\u73fe<br \/>\n\u9084\u6709\u8def\u6bb5\u7684`\u58c5\u585e\u7a0b\u5ea6`<\/p>\n","protected":false},"author":1,"featured_media":559,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-425","post","type-post","status-publish","format-aside","has-post-thumbnail","hentry","category-swift","post_format-post-format-aside"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2020\/11\/cup-1-1.png","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-6R","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=425"}],"version-history":[{"count":3,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/425\/revisions"}],"predecessor-version":[{"id":567,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/425\/revisions\/567"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/559"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}