{"id":1215,"date":"2025-05-30T10:55:36","date_gmt":"2025-06-05T03:39:35","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=1215"},"modified":"2025-06-05T10:55:36","modified_gmt":"2025-06-05T03:39:35","slug":"swift-%e5%9c%b0%e5%9d%80%e8%bd%89%e7%b6%93%e7%b7%af%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/swift-%e5%9c%b0%e5%9d%80%e8%bd%89%e7%b6%93%e7%b7%af%e5%ba%a6\/","title":{"rendered":"Swift \u5730\u5740\u8f49\u7d93\u7def\u5ea6\u6307\u5357\uff1a\u4f7f\u7528 CLGeocoder \u7372\u53d6\u6e96\u78ba\u4f4d\u7f6e (2025 \u6700\u65b0\u8a9e\u6cd5)"},"content":{"rendered":"<h2>Swift \u5730\u5740\u8f49\u7d93\u7def\u5ea6\u6307\u5357<\/h2>\n<h3>\u6e2c\u8a66\u5730\u5740<\/h3>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2021\/04\/wp_editor_md_532a5fd4b5e708fdf2c22fc7cab5e9dd.jpg\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2021\/04\/wp_editor_md_532a5fd4b5e708fdf2c22fc7cab5e9dd.jpg\" alt=\"Swift \u5730\u5740\u8f49\u7d93\u7def\u5ea6\u793a\u7bc4\" title=\"\"><\/a><\/p>\n<h3>\u4f7f\u7528 CLGeocoder \u8f49\u63db\u5730\u5740\u70ba\u7d93\u7def\u5ea6<\/h3>\n<p>\u5728 Swift \u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 `CLGeocoder` \u4f86\u5c07\u5730\u5740\u8f49\u63db\u70ba\u7d93\u7def\u5ea6\u3002\u4ee5\u4e0b\u662f\u5b8c\u6574\u7684\u5be6\u4f5c\u7bc4\u4f8b\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nimport MapKit<\/p>\n<p>let geoCoder = CLGeocoder()<br \/>\nlet address = &#8220;\u53f0\u4e2d\u5e02\u5357\u5340\u5fa9\u8208\u8def\u4e00\u6bb5460\u865f&#8221;<\/p>\n<p>geoCoder.geocodeAddressString(address) { (placemarks, error) in<br \/>\n    if let error = error {<br \/>\n        print(&#8220;\u932f\u8aa4: \\(error.localizedDescription)&#8221;)<br \/>\n        return<br \/>\n    }<\/p>\n<p>    guard let placemarks = placemarks, !placemarks.isEmpty else {<br \/>\n        print(&#8220;\u672a\u627e\u5230\u4f4d\u7f6e&#8221;)<br \/>\n        return<br \/>\n    }<\/p>\n<p>    let placemark = placemarks[0]\n    if let location = placemark.location {<br \/>\n        let latitude = location.coordinate.latitude<br \/>\n        let longitude = location.coordinate.longitude<br \/>\n        print(&#8220;\u7d93\u5ea6: \\(longitude), \u7def\u5ea6: \\(latitude)&#8221;)<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u5c07\u6307\u5b9a\u7684\u5730\u5740\u8f49\u63db\u70ba\u7d93\u7def\u5ea6\uff0c\u4e26\u8f38\u51fa\u7d50\u679c\u3002<\/p>\n<h3>\u6e2c\u8a66 Google \u5730\u5716\u7db2\u5740<\/h3>\n<p>\u4f7f\u7528\u7d93\u7def\u5ea6\u4f86\u751f\u6210 Google \u5730\u5716\u7db2\u5740\uff0c\u65b9\u4fbf\u67e5\u770b\u4f4d\u7f6e\uff1a<\/p>\n<p>&#8211; [Google \u5730\u5716\u9023\u7d50](http:\/\/maps.google.com\/?q=\u7d93\u5ea6,\u7def\u5ea6)<br \/>\n&#8211; [\u76f4\u63a5\u9023\u7d50\u81f3\u6e2c\u8a66\u5730\u5740](http:\/\/maps.google.com\/?q=24.11682100,120.65772300)<\/p>\n<h3>\u7d50\u679c<\/h3>\n<p>\u6839\u64da\u4e0a\u8ff0\u7bc4\u4f8b\uff0c\u60a8\u53ef\u80fd\u6703\u6ce8\u610f\u5230\u7d93\u7def\u5ea6\u7684\u6e96\u78ba\u6027\u6703\u6709\u4e00\u5b9a\u7684\u7bc4\u570d\uff0c\u4f8b\u5982 +\/- 100.00m\u3002\u5982\u679c\u9700\u8981\u66f4\u9ad8\u7684\u6e96\u78ba\u5ea6\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528 Google Places API\uff0c\u4f46\u9019\u53ef\u80fd\u6703\u7522\u751f\u8cbb\u7528\u3002<\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2021\/04\/wp_editor_md_bafe15b8230f9eb581a3e2c5378f1d09.jpg\"><img decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2021\/04\/wp_editor_md_bafe15b8230f9eb581a3e2c5378f1d09.jpg\" alt=\"CLGeocoder \u4f7f\u7528\u7bc4\u4f8b\" title=\"\"><\/a><\/p>\n<h3>\u932f\u8aa4\u6392\u9664<\/h3>\n<p>\u5728\u4f7f\u7528 `CLGeocoder` \u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u932f\u8aa4\uff1a<br \/>\n&#8211; \u5982\u679c\u5730\u5740\u4e0d\u6b63\u78ba\u6216\u683c\u5f0f\u4e0d\u6b63\u78ba\uff0c\u5247\u53ef\u80fd\u7121\u6cd5\u627e\u5230\u76f8\u61c9\u7684\u7d93\u7def\u5ea6\u3002<br \/>\n&#8211; \u78ba\u4fdd\u8a2d\u5099\u5df2\u9023\u63a5\u5230\u7db2\u8def\uff0c\u56e0\u70ba\u5730\u7406\u7de8\u78bc\u9700\u8981\u7db2\u8def\u670d\u52d9\u3002<\/p>\n<h3>\u5ef6\u4f38\u61c9\u7528<\/h3>\n<p>&#8211; \u5c07\u9019\u500b\u529f\u80fd\u6574\u5408\u5230\u60a8\u7684\u61c9\u7528\u4e2d\uff0c\u8b93\u4f7f\u7528\u8005\u53ef\u4ee5\u900f\u904e\u8f38\u5165\u5730\u5740\u4f86\u7372\u53d6\u5730\u7406\u4f4d\u7f6e\u3002<br \/>\n&#8211; \u7d50\u5408\u5730\u5716\u986f\u793a\u529f\u80fd\uff0c\u5c07\u7372\u53d6\u7684\u7d93\u7def\u5ea6\u6a19\u793a\u5728\u5730\u5716\u4e0a\u3002<\/p>\n<h2>\u5e38\u898b\u554f\u984c\u89e3\u7b54 (Q&#038;A)<\/h2>\n<h3>1. CLGeocoder \u7684\u4f7f\u7528\u9650\u5236\u662f\u4ec0\u9ebc\uff1f<\/h3>\n<p>CLGeocoder \u5728\u4f7f\u7528\u6642\u6703\u53d7\u5230 Apple \u7684 API \u9650\u5236\uff0c\u904e\u65bc\u983b\u7e41\u7684\u8acb\u6c42\u53ef\u80fd\u6703\u5c0e\u81f4\u670d\u52d9\u88ab\u66ab\u6642\u5c01\u9396\u3002<\/p>\n<h3>2. \u5982\u4f55\u63d0\u9ad8\u5730\u5740\u8f49\u63db\u7684\u6e96\u78ba\u6027\uff1f<\/h3>\n<p>\u4f7f\u7528\u66f4\u5177\u9ad4\u7684\u5730\u5740\u4fe1\u606f\uff0c\u4f8b\u5982\u5305\u542b\u90f5\u653f\u7de8\u78bc\u548c\u57ce\u5e02\u540d\u7a31\uff0c\u53ef\u4ee5\u63d0\u9ad8\u8f49\u63db\u7684\u6e96\u78ba\u6027\u3002<\/p>\n<h3>3. \u4f7f\u7528 Google Places API \u6709\u54ea\u4e9b\u512a\u52e2\uff1f<\/h3>\n<p>Google Places API \u63d0\u4f9b\u4e86\u66f4\u9ad8\u7684\u6e96\u78ba\u5ea6\u548c\u66f4\u591a\u7684\u5730\u7406\u6578\u64da\uff0c\u4f46\u9700\u8981\u4ed8\u8cbb\u4f7f\u7528\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Swift \u5730\u5740\u8f49\u7d93\u7def\u5ea6\u6307\u5357 \u6e2c\u8a66\u5730\u5740 \u4f7f\u7528 CL&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-1215","post","type-post","status-publish","format-aside","hentry","category-swift","post_format-post-format-aside"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-jB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/1215","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=1215"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/1215\/revisions"}],"predecessor-version":[{"id":1216,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/1215\/revisions\/1216"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=1215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=1215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=1215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}