{"id":2376,"date":"2024-08-16T16:05:45","date_gmt":"2024-08-16T07:05:45","guid":{"rendered":"https:\/\/secondlife.lol\/?p=2376"},"modified":"2024-08-16T22:10:54","modified_gmt":"2024-08-16T13:10:54","slug":"python-map-visualization-travel-route","status":"publish","type":"post","link":"https:\/\/secondlife.lol\/zh\/python-map-visualization-travel-route\/","title":{"rendered":"Python \u5730\u56fe\u53ef\u89c6\u5316\uff1a\u83b7\u5f97\u6c38\u4e0d\u540e\u6094\u7684\u8def\u7ebf\uff08\u7279\u8272\uff1afolium \u8f6f\u4ef6\u5305\uff09"},"content":{"rendered":"<p>\u5f53\u4f60\u8ba1\u5212\u53bb\u4e00\u4e2a\u4ece\u672a\u53bb\u8fc7\u7684\u5730\u65b9\u65c5\u884c\u65f6\uff0c\u4f60\u662f\u5426\u5e0c\u671b\u80fd\u770b\u5230\u6574\u4e2a\u65c5\u884c\u8def\u7ebf\uff1f\u5728\u4eca\u5929\u7684\u6587\u7ae0\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 Python \u5730\u56fe\u53ef\u89c6\u5316\u6280\u672f\u5c06\u65c5\u884c\u8def\u7ebf\u53ef\u89c6\u5316\u3002 \u6211\u4eec\u5c06\u4f7f\u7528 Python \u5f3a\u5927\u7684 <strong><a href=\"https:\/\/python-visualization.github.io\/folium\/\" data-type=\"link\" data-id=\"https:\/\/python-visualization.github.io\/folium\/\" target=\"_blank\" rel=\"noopener\">\u4e66\u5e93<\/a><\/strong>\u4ee5\u76f4\u89c2\u7684\u65b9\u5f0f\u9010\u6b65\u5448\u73b0\u8fd9\u4e00\u65c5\u7a0b\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5047\u8bbe\u60c5\u51b5 <strong>\u80af\u5c3c\u8fea\u673a\u573a<\/strong>\u4e58\u5750\u51fa\u79df\u8f66\u6216\u4f18\u6b65\u524d\u5f80 <strong>\u7ebd\u7ea6\u4e2d\u57ce\u5e0c\u5c14\u987f\u9152\u5e97<\/strong> \u62b5\u8fbe\u9152\u5e97\u540e\uff0c\u6b65\u884c\u524d\u5f80 <strong>\u66fc\u54c8\u987f\u4e2d\u5fc3<\/strong> \u524d\u5f80\u4f1a\u573a\u3002\u901a\u8fc7\u672c\u6559\u7a0b\u3001 <strong>Python \u5730\u56fe\u53ef\u89c6\u5316<\/strong> \u638c\u63e1\u6280\u80fd\uff0c\u5b66\u4e60\u5982\u4f55\u5728\u5730\u56fe\u4e0a\u7ed8\u5236\u65c5\u884c\u8def\u7ebf\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e86\u89e3 Python \u5730\u56fe\u53ef\u89c6\u5316\u6458\u8981<\/h2>\n\n\n\n<p>Python \u5730\u56fe\u53ef\u89c6\u5316\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4f7f\u7528 GPS \u5750\u6807\u5728\u5730\u56fe\u4e0a\u76f4\u89c2\u5730\u663e\u793a\u5404\u79cd\u6570\u636e\u3002 \u7279\u522b\u662f\uff0c\u901a\u8fc7 folium \u5e93\uff0c\u60a8\u53ef\u4ee5\u5728 Python \u4e2d\u521b\u5efa\u7c7b\u4f3c\u8c37\u6b4c\u5730\u56fe\u7684\u5730\u56fe\u3002 <\/p>\n\n\n\n<p>\u5728\u672c\u793a\u4f8b\u4e2d\uff0c\u60a8\u5c06\u770b\u5230\u5982\u4f55\u4e3a\u7ebd\u7ea6\u5e02\u7684\u4e09\u4e2a\u5173\u952e\u70b9\uff08\u80af\u5c3c\u8fea\u673a\u573a\u3001\u7ebd\u7ea6\u4e2d\u57ce\u5e0c\u5c14\u987f\u9152\u5e97\u548c\u66fc\u54c8\u987f\u4e2d\u5fc3\u4f1a\u573a\uff09\u6dfb\u52a0\u6807\u8bb0\uff0c\u663e\u793a\u8fde\u63a5\u5b83\u4eec\u7684\u84dd\u7ebf\uff0c\u5e76\u5728\u5730\u56fe\u4e0a\u663e\u793a\u65c5\u884c\u65f6\u95f4\u548c\u8ddd\u79bb\u4fe1\u606f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u9010\u6b65\u7f16\u5199 Python \u4ee3\u7801<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u5b89\u88c5\u5e76\u52a0\u8f7d\u7a0b\u5e8f\u5e93<\/h3>\n\n\n\n<p>\u8981\u5728 Python \u4e2d\u5c06\u5730\u56fe\u53ef\u89c6\u5316\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>\u53f6\u7247<\/code> \u5b89\u88c5\u5e76\u5bfc\u5165\u7a0b\u5e8f\u5e93\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5bfc\u5165\u6240\u9700\u5e93\u51fd\u6570\n\u5bfc\u5165 os # \u6a21\u5757\uff0c\u7528\u4e8e\u64cd\u4f5c\u6587\u4ef6\u548c\u76ee\u5f55\n\u5bfc\u5165 folium # \u7528\u4e8e\u521b\u5efa\u548c\u64cd\u4f5c\u5730\u56fe\u7684\u5e93\n\n\u521b\u5efa\u4e00\u4e2a\u7528\u4e8e\u5b58\u50a8 # \u7ed3\u679c\u7684\u76ee\u5f55\nresult_dir = 'C:\/result\/'\n# os.makedirs()\uff1a\u521b\u5efa\u76ee\u5f55\u3002\u9009\u9879 exist_ok=True \u53ef\u907f\u514d\u5728\u76ee\u5f55\u5df2\u5b58\u5728\u65f6\u51fa\u9519\nos.makedirs(result_dir, exist_ok=True)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u8bbe\u7f6e\u5173\u952e\u4f4d\u7f6e\u4ee5\u53ca\u8ddd\u79bb\u548c\u65f6\u95f4\u6570\u636e<\/h3>\n\n\n\n<p>\u786e\u5b9a\u6bcf\u4e2a\u5730\u70b9\u7684 GPS \u5750\u6807\uff0c\u8bbe\u5b9a\u4e24\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u548c\u9884\u8ba1\u65f6\u95f4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4e3b\u8981\u5730\u70b9\u7684\u5730\u7406\u5750\u6807\uff08\u7eac\u5ea6\u3001\u7ecf\u5ea6\uff09\nsimplified_locations = {\n    \"\u80af\u5c3c\u8fea\u673a\u573a[40.6413, -73.7781],\n    \"Hilton New York Midtown\"\uff1a[40.7625, -73.9780],\n    \u6d3b\u52a8\u573a\u5730\uff08\u66fc\u54c8\u987f\u4e2d\u5fc3\uff09\"\uff1a [40.7527, -73.7781], \"Hilton New York Midtown\": [40.7625, -73.9780], \"Event Venue (Manhattan Centre)\"\uff1a[40.7527, -73.9932]\n}\n\n# \u8ddd\u79bb\uff08\u5343\u7c73\uff09\u548c\u65f6\u95f4\uff08\u5206\u949f\uff09\u4fe1\u606f\n\u7b80\u5316\u7684\u8ddd\u79bb\u548c\u65f6\u95f4 = {\n    (\"JFK Airport\", \"Hilton New York Midtown\"): (25.0, 35)\u3001\n    (\u7ebd\u7ea6\u4e2d\u57ce\u5e0c\u5c14\u987f\u9152\u5e97\"\u3001\"\u6d3b\u52a8\u573a\u5730\uff08\u66fc\u54c8\u987f\u4e2d\u5fc3\uff09\"\uff09\uff1a (1.2, 15)\n}\n\n\u8bbe\u7f6e # \u8def\u7531\u987a\u5e8f\nordered_locations = [\n    (\"JFK Airport\", \"Hilton New York Midtown\")\u3001\n    (\"\u7ebd\u7ea6\u4e2d\u57ce\u5e0c\u5c14\u987f\u9152\u5e97\"\u3001\"\u6d3b\u52a8\u573a\u5730\uff08\u66fc\u54c8\u987f\u4e2d\u5fc3\uff09\")\n]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u7ed8\u5236\u5730\u56fe\u5e76\u5c06\u8def\u7ebf\u53ef\u89c6\u5316<\/h3>\n\n\n\n<p>\u7ed8\u5236\u4ee5\u7ebd\u7ea6\u4e3a\u4e2d\u5fc3\u7684\u5730\u56fe\uff0c\u5728\u6bcf\u4e2a\u70b9\u4e0a\u6dfb\u52a0\u7f16\u53f7\u6807\u8bb0\uff0c\u5e76\u7528\u84dd\u7ebf\u8fde\u63a5\u8def\u7ebf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u521b\u5efa # \u5730\u56fe\n# folium.Map()\uff1a\u521b\u5efa\u57fa\u672c\u5730\u56fe\n# location\uff1a\u5730\u56fe\u4e2d\u5fc3\u70b9\u5750\u6807[\u7eac\u5ea6\uff0c\u7ecf\u5ea6]\u3002\n# zoom_start\uff1a\u521d\u59cb\u7f29\u653e\u7ea7\u522b\uff08\u8d8a\u9ad8\u7f29\u653e\u8d8a\u591a\uff09\nm = folium.Map(location=[40.7200, -73.9000], zoom_start=11)\n\n# \u6dfb\u52a0\u6807\u8bb0\u548c\u8def\u5f84\n# enumerate()\uff1a\u8fd4\u56de\u5217\u8868\u5143\u7d20\u53ca\u5176\u7d22\u5f15\uff0c\u7d22\u5f15\u4ece 1 \u5f00\u59cb\uff0cstart=1\nfor idx, location in enumerate(simplified_locations.items(), start=1)\uff1a\n    loc_name, coords = location\n    # folium.Marker()\uff1a\u5728\u5730\u56fe\u4e0a\u6dfb\u52a0\u6807\u8bb0\n    # \u5f39\u51fa\u7a97\u53e3\uff1a\u70b9\u51fb\u6807\u8bb0\u65f6\u663e\u793a\u7684\u6587\u672c\n    # \u56fe\u6807\uff1a\u8bbe\u7f6e\u6807\u8bb0\u7684\u5916\u89c2\n    folium.Marker(\n        coords\u3001\n        popup=f&quot;{idx}.{loc_name}&quot;\u3001\n        icon=folium.DivIcon(\n            html=f&quot;&quot;&quot;&quot;\n            &lt;div style=&quot;text-align: center;&quot;&gt;\n                &lt;div style=&quot;font-size: 12pt; font-weight: bold; color: black; background-color: white; border-radius: 50%;                 width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;&quot;&gt;\n                {idx}\n                &lt;\/div&gt;\n                &lt;div style=&quot;font-size: 10pt; font-weight: bold; color: navy; margin-top: 10px;&quot;&gt;\n                {\u5730\u70b9\u540d\u79f0\uff5d\n                &lt;\/div&gt;\n            &lt;\/div&gt;&quot;&quot;&quot;\n        )\n    ).add_to(m)\n\n# \u6dfb\u52a0\u8def\u7ebf\u548c\u8ddd\u79bb\/\u65f6\u95f4\u4fe1\u606f\nfor (loc1, loc2) in ordered_locations\uff1a\n    # folium.PolyLine()\uff1a\u5728\u4e24\u70b9\u4e4b\u95f4\u753b\u4e00\u6761\u76f4\u7ebf\n    # color\uff1a\u76f4\u7ebf\u7684\u989c\u8272\uff1bweight\uff1a\u76f4\u7ebf\u7684\u7c97\u7ec6\uff1bopacity\uff1a\u76f4\u7ebf\u7684\u900f\u660e\u5ea6\n    folium.PolyLine([simplified_locations[loc1], simplified_locations[loc2]], color=&quot;blue&quot;, weight=2.5, opacity=1).add_to(m)\n\n    # \u83b7\u53d6\u8ddd\u79bb\u548c\u65f6\u95f4\u4fe1\u606f\n    distance_km, time_min = simplified_distances_and_times[(loc1, loc2)] \u8ddd\u79bb\u548c\u65f6\u95f4\u4fe1\u606f\n    # \u8ba1\u7b97\u4e24\u70b9\u7684\u4e2d\u70b9\u5750\u6807\n    mid_point = [(simplified_locations[loc1][0] + simplified_locations[loc2][0]) \/ 2\u3001\n                 (simplified_locations[loc1][1] + simplified_locations[loc2][1]) \/ 2\uff3d\n    \u5728 # \u7684\u4e2d\u70b9\u6dfb\u52a0\u5305\u542b\u8ddd\u79bb\u548c\u65f6\u95f4\u4fe1\u606f\u7684\u6807\u8bb0\n    folium.Marker(\n        mid_point\u3001\n        icon=folium.DivIcon(\n            html=f'&lt;div style=&quot;font-size: 10pt; font-weight: bold; color: red;&quot;&gt;{\u8ddd\u79bb_\u516c\u91cc}\u516c\u91cc\uff0c{\u65f6\u95f4_\u5206\u949f}\u5206\u949f&lt;\/div&gt;',\n        )\n    ).add_to(m)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4fdd\u5b58\u5730\u56fe<\/h3>\n\n\n\n<p>\u5c06\u5b8c\u6210\u7684\u5730\u56fe\u4fdd\u5b58\u5230\u672c\u5730\u8ba1\u7b97\u673a\u7684 <code>C:\\result<\/code> \u6587\u4ef6\u5939\uff0c\u5982\u679c\u6210\u529f\u5b8c\u6210\uff0c\u5219\u4f1a\u8f93\u51fa\u4fdd\u5b58\u5730\u56fe html \u6587\u4ef6\u7684\u8def\u5f84\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5c06\u5730\u56fe\u4fdd\u5b58\u4e3a HTML\n# os.path.join()\uff1a\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7279\u6709\u7684\u8def\u5f84\u5206\u9694\u7b26\u751f\u6210\u6587\u4ef6\u8def\u5f84\nfinal_corrected_map_path = os.path.join(result_dir, 'ny_business_trip_final_corrected_map_with_distances.html')\nm.save(final_corrected_map_path) # \u5c06\u751f\u6210\u7684\u5730\u56fe\u4fdd\u5b58\u4e3a HTML \u6587\u4ef6\n\nprint(f \"Map saved to: {final_corrected_map_path}\") # \u6253\u5370\u4fdd\u5b58\u6587\u4ef6\u7684\u8def\u5f84<\/code><\/pre>\n\n\n<style>.kb-image2376_945213-a0 .kb-image-has-overlay:after{opacity:0.3;}<\/style>\n<div class=\"wp-block-kadence-image kb-image2376_945213-a0\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"570\" height=\"21\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-4.jpg\" alt=\"\ud30c\uc774\uc36c \uc9c0\ub3c4 \uc2dc\uac01\ud654 \ucf54\ub4dc \uc2e4\ud589 \uacb0\uacfc \ud45c\uc2dc\" class=\"kb-img wp-image-2378\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-4.jpg 570w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-4-300x11.jpg 300w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><figcaption>(\u8fd0\u884c\u6e90\u4ee3\u7801\u540e\u7ec8\u7aef\u4e0a\u7684\u4fe1\u606f\uff09<\/figcaption><\/figure><\/div>\n\n\n\n<p>\u8981\u5728\u6d4f\u89c8\u5668\u4e2d\u67e5\u770b\u5b8c\u6210\u7684\u5730\u56fe\uff0c\u53ea\u9700\u70b9\u51fb\u5176\u6587\u4ef6\u5939\u4e2d\u7684 HTML \u6587\u4ef6\uff08\u5982\u4e0b\u56fe\u6240\u793a\uff09\uff0c\u5c31\u80fd\u770b\u5230\u6211\u4eec\u6240\u8981\u6c42\u7684\u5185\u5bb9\u3002<\/p>\n\n\n<style>.kb-image2376_7dbbef-84 .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image2376_7dbbef-84 img.kb-img, .kb-image2376_7dbbef-84 .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image2376_7dbbef-84\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"401\" height=\"176\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-5.jpg\" alt=\"\ud30c\uc774\uc36c \uc9c0\ub3c4 \uc2dc\uac01\ud654 \uc18c\uc2a4\ucf54\ub4dc \uc2e4\ud589\uacb0\uacfc\ubb3c \ud3f4\ub354 \uc0ac\uc9c4\" class=\"kb-img wp-image-2379\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-5.jpg 401w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-5-300x132.jpg 300w\" sizes=\"(max-width: 401px) 100vw, 401px\" \/><figcaption>(\u5b58\u50a8\u5728\u6e90\u4ee3\u7801\u6267\u884c\u7ed3\u679c\u6587\u4ef6\u5939\u4e2d\u7684 HTML \u6587\u4ef6\uff09<\/figcaption><\/figure><\/div>\n\n\n<style>.kb-image2376_2ab125-15 .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image2376_2ab125-15 img.kb-img, .kb-image2376_2ab125-15 .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image2376_2ab125-15\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"600\" height=\"448\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-6-600x448.jpg\" alt=\"\ud30c\uc774\uc36c \uc9c0\ub3c4 \uc2dc\uac01\ud654 \uc18c\uc2a4\ucf54\ub4dc \uc2e4\ud589\uacb0\uacfc \uc0dd\uc131\ub41c \uc9c0\ub3c4 \uc0ac\uc9c4\" class=\"kb-img wp-image-2380\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-6-600x448.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-6-300x224.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-6-768x573.jpg 768w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-6.jpg 813w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption>(\u8fd0\u884c\u6e90\u4ee3\u7801\u751f\u6210\u7684\u5730\u56fe\uff09<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u5e38\u89c1\u95ee\u9898\uff08FAQ\uff09<\/h2>\n\n\n\n<p><strong>Q1. \u5728 Python \u5730\u56fe\u53ef\u89c6\u5316\u4e2d <code>\u53f6\u7247<\/code>\u6709\u5417\uff1f<\/strong><br>A1. <code>\u53f6\u7247<\/code>\u662f\u4e00\u4e2a\u53ef\u4ee5\u5e2e\u52a9\u60a8\u4f7f\u7528 Python \u53ef\u89c6\u5316\u5730\u56fe\u6570\u636e\u7684\u5e93\u3002\u5b83\u80fd\u8ba9\u60a8\u4ee5\u4e0e\u8c37\u6b4c\u5730\u56fe\u76f8\u540c\u7684\u65b9\u5f0f\u76f4\u89c2\u5730\u663e\u793a\u6570\u636e\u3002<\/p>\n\n\n\n<p><strong>Q2. \u5982\u4f55\u627e\u5230\u5750\u6807\uff1f<\/strong><br>A2. \u4f7f\u7528\u8c37\u6b4c\u5730\u56fe\u641c\u7d22\u60a8\u60f3\u8981\u7684\u4f4d\u7f6e\uff0c\u7136\u540e\u53f3\u952e\u5355\u51fb\u4f4d\u7f6e\u56fe\u6807\uff0c\u9009\u62e9\u5750\u6807\uff0840.648275456129724\uff0c-73.78004682462297\uff09\u8fdb\u884c\u590d\u5236\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"600\" height=\"300\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-7-600x300.jpg\" alt=\"\" class=\"wp-image-2383\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-7-600x300.jpg 600w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-7-300x150.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-7.jpg 678w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure>\n<\/div>\n\n\n<p><strong>\u95ee\u9898 3\uff1a \u80fd\u5426\u5c06\u66f4\u590d\u6742\u7684\u8def\u5f84\u53ef\u89c6\u5316\uff1f<\/strong><br>\u7b543\uff1a \u53ef\u4ee5\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u66f4\u591a\u5730\u70b9\u3001\u663e\u793a\u5b9e\u65f6\u4ea4\u901a\u4fe1\u606f\u7b49\u65b9\u5f0f\u5bf9\u5176\u8fdb\u884c\u6269\u5c55\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u7684\u6e90\u4ee3\u7801\u544a\u8bc9\u4eba\u5de5\u667a\u80fd\u4f60\u60f3\u70b9\u4ec0\u4e48\uff0c\u7136\u540e\u8ba9\u5b83\u4e3a\u4f60\u7f16\u7801\u3002 <\/p>\n\n\n\n<p><strong>Q4. \u80fd\u5426\u5c06 Python \u5730\u56fe\u53ef\u89c6\u5316\u7684\u7ed3\u679c\u4fdd\u5b58\u4e3a\u56fe\u50cf\uff1f<\/strong><br>A4. <code>\u53f6\u7247<\/code>\u9ed8\u8ba4\u4fdd\u5b58\u4e3a HTML \u6587\u4ef6\u3001 <code>\u7852<\/code>(\u6211\u4eec\u5c06\u5728\u53e6\u4e00\u7bc7\u6587\u7ae0\u4e2d\u4ecb\u7ecd\uff09\uff0c\u6216\u8005\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u975e\u7a0b\u5e8f\u5316\u7684 <strong>\u952e\u76d8\u5feb\u6377\u952e\uff08win+shift+s\uff09<\/strong>\u6765\u6355\u6349\u4ee5 HTML \u663e\u793a\u7684\u5730\u56fe\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ec4\u7ec7\u8d77\u6765<\/h2>\n\n\n\n<p>\u5728\u672c\u7bc7\u535a\u6587\u4e2d\uff0c\u60a8\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 Python \u5730\u56fe\u53ef\u89c6\u5316\u6765\u76f4\u89c2\u5730\u5c55\u793a\u7ebd\u7ea6\u5e02\u7684\u65c5\u884c\u8def\u7ebf\u3002 \u8fd9\u4e00\u8fc7\u7a0b\u53ef\u4ee5\u8ba9\u60a8\u76f4\u89c2\u5730\u7406\u89e3\u6570\u636e\uff0c\u5373\u4f7f\u662f\u590d\u6742\u7684\u65c5\u884c\u8def\u7ebf\u6216\u7269\u6d41\u8fd0\u52a8\u4e5f\u80fd\u8f7b\u677e\u5b9e\u73b0\u53ef\u89c6\u5316\u3002\u5206\u4eab\u672c\u6587\u7ae0 <a href=\"https:\/\/secondlife.lol\/zh\/guide-for-ai-prompting-effectively\/\" data-type=\"post\" data-id=\"1495\">\u4eba\u5de5\u667a\u80fd\u63d0\u793a\u5185\u5bb9<\/a>\u4ee5\u53ef\u89c6\u5316\u4e0d\u540c\u7684\u65c5\u884c\u8def\u7ebf\uff0c\u6216\u4e3a\u6269\u5c55\u9879\u76ee\u6dfb\u52a0\u66f4\u591a\u6570\u636e\uff01<\/p>\n\n\n\n<p>\u5982\u679c\u60a8\u6b63\u5728\u51c6\u5907\u4e00\u4efd\u5b8c\u6574\u7684\u65c5\u884c\u8ba1\u5212\uff0c\u5305\u62ec\u9884\u7b97\u3001\u884c\u7a0b\u548c Python \u5730\u56fe\u53ef\u89c6\u5316\uff0c\u8bf7\u67e5\u770b\u8fd9\u7bc7\u6587\u7ae0 (<a href=\"https:\/\/secondlife.lol\/zh\/perfect-travel-itinerary-with-chatgpt4\/\" data-type=\"post\" data-id=\"2305\">\u60a8\u80fd\u4e3a 2024 \u5e74\u6625\u8282\u8ba1\u5212\u4e00\u6b21 ChatGPT \u65c5\u884c\u5417\uff1f<\/a>)\uff0c\u8fd9\u5c06\u7ed9\u4f60\u5e26\u6765\u53e6\u4e00\u79cd\u542f\u793a\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1TP5\u5b8c\u6574\u96c6\u6210\u4ee3\u7801<\/h4>\n\n\n\n<p>\u5c06\u4e0b\u9762\u7684\u4ee3\u7801\u590d\u5236\u5e76\u7c98\u8d34\u5230\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08\u5982 VS \u4ee3\u7801\uff09\u4e2d\u5e76\u6267\u884c\u3002 \u4f46\u662f\uff0c\u5982\u679c\u672a\u5b89\u88c5 folium \u8f6f\u4ef6\u5305\uff0c\u5219\u4f1a\u51fa\u73b0\u4ee5\u4e0b\u8b66\u544a\u3002\u4f60\u53ef\u4ee5\u5728\u7ec8\u7aef\u4f7f\u7528 pip install folium \u547d\u4ee4\uff08pip install folium\uff09\u5b89\u88c5\u8f6f\u4ef6\u5305\uff0c\u7136\u540e\u6267\u884c\u4e0b\u9762\u7684\u96c6\u6210\u4ee3\u7801\u3002<\/p>\n\n\n<style>.kb-image2376_abd982-07 .kb-image-has-overlay:after{opacity:0.3;}<\/style>\n<div class=\"wp-block-kadence-image kb-image2376_abd982-07\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"533\" height=\"70\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-3.jpg\" alt=\"\ud30c\uc774\uc36c \uc9c0\ub3c4 \uc2dc\uac01\ud654 \ud328\ud0a4\uc9c0 \uc124\uce58\uc2dc \uc54c\ub78c\" class=\"kb-img wp-image-2377\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-3.jpg 533w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/image-1-3-300x39.jpg 300w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><figcaption>(\u672a\u5b89\u88c5\u5bf9\u5f00\u5305\u65f6\u4f1a\u53d1\u51fa\u8b66\u62a5\uff09<\/figcaption><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5bfc\u5165\u6240\u9700\u5e93\u51fd\u6570\n\u5bfc\u5165 os # \u6a21\u5757\uff0c\u7528\u4e8e\u6587\u4ef6\u7cfb\u7edf\u64cd\u4f5c\uff08\u76ee\u5f55\u521b\u5efa\u3001\u6587\u4ef6\u8def\u5f84\u64cd\u4f5c\u7b49\uff09\n\u5bfc\u5165 folium # \u7528\u4e8e\u521b\u5efa\u4ea4\u4e92\u5f0f\u5730\u56fe\u7684\u5e93\n\n\u521b\u5efa\u4e00\u4e2a\u7528\u4e8e\u5b58\u50a8 # \u7ed3\u679c\u7684\u76ee\u5f55\nresult_dir = 'C:\/result\/'\n# os.makedirs()\uff1a\u521b\u5efa\u76ee\u5f55\u3002\u9009\u9879 exist_ok=True \u53ef\u907f\u514d\u5728\u76ee\u5f55\u5df2\u5b58\u5728\u65f6\u51fa\u9519\nos.makedirs(result_dir, exist_ok=True)\n\n# \u8bbe\u7f6e\u5173\u952e\u5730\u70b9\u7684\u5750\u6807\uff08\u7eac\u5ea6\u3001\u7ecf\u5ea6\uff09\nsimplified_locations = {\n    &quot;\u80af\u5c3c\u8fea\u673a\u573a[40.6413, -73.7781],\n    &quot;Hilton New York Midtown&quot;\uff1a[40.7625, -73.9780],\n    \u6d3b\u52a8\u573a\u5730\uff08\u66fc\u54c8\u987f\u4e2d\u5fc3\uff09&quot;\uff1a [40.7527, -73.7781], &quot;Hilton New York Midtown&quot;: [40.7625, -73.9780], &quot;Event Venue (Manhattan Centre)&quot;\uff1a[40.7527, -73.9932]\n}\n\n# \u8ddd\u79bb\uff08\u5343\u7c73\uff09\u548c\u65f6\u95f4\uff08\u5206\u949f\uff09\u4fe1\u606f\n\u7b80\u5316\u7684\u8ddd\u79bb\u548c\u65f6\u95f4 = {\n    (&quot;JFK Airport&quot;, &quot;Hilton New York Midtown&quot;): (25.0, 35)\u3001\n    (\u7ebd\u7ea6\u4e2d\u57ce\u5e0c\u5c14\u987f\u9152\u5e97&quot;\u3001&quot;\u6d3b\u52a8\u573a\u5730\uff08\u66fc\u54c8\u987f\u4e2d\u5fc3\uff09&quot;\uff09\uff1a (1.2, 15)\n}\n\n\u8bbe\u7f6e # \u8def\u7531\u987a\u5e8f\nordered_locations = [\n    (&quot;JFK Airport&quot;, &quot;Hilton New York Midtown&quot;)\u3001\n    (&quot;\u7ebd\u7ea6\u4e2d\u57ce\u5e0c\u5c14\u987f\u9152\u5e97&quot;\u3001&quot;\u6d3b\u52a8\u573a\u5730\uff08\u66fc\u54c8\u987f\u4e2d\u5fc3\uff09&quot;)\n]\n\n# \u521b\u5efa\u5730\u56fe\n# folium.Map()\uff1a\u521b\u5efa\u57fa\u672c\u5730\u56fe\n# location\uff1a\u5730\u56fe\u4e2d\u5fc3\u70b9\u5750\u6807[\u7eac\u5ea6\uff0c\u7ecf\u5ea6]\u3002\n# zoom_start\uff1a\u521d\u59cb\u7f29\u653e\u7ea7\u522b\uff08\u8d8a\u9ad8\u7f29\u653e\u8d8a\u591a\uff09\nm = folium.Map(location=[40.7200, -73.9000], zoom_start=11)\n\n# \u6dfb\u52a0\u6807\u8bb0\u548c\u8def\u5f84\n# enumerate()\uff1a\u8fd4\u56de\u5217\u8868\u5143\u7d20\u53ca\u5176\u7d22\u5f15\uff0c\u7d22\u5f15\u4ece 1 \u5f00\u59cb\uff0cstart=1\nfor idx, location in enumerate(simplified_locations.items(), start=1)\uff1a\n    loc_name, coords = location\n    # folium.Marker()\uff1a\u5728\u5730\u56fe\u4e0a\u6dfb\u52a0\u6807\u8bb0\n    # \u5f39\u51fa\u7a97\u53e3\uff1a\u70b9\u51fb\u6807\u8bb0\u65f6\u663e\u793a\u7684\u6587\u672c\n    # \u56fe\u6807\uff1a\u8bbe\u7f6e\u6807\u8bb0\u7684\u5916\u89c2\n    folium.Marker(\n        coords\u3001\n        popup=f&quot;{idx}.{loc_name}&quot;\u3001\n        icon=folium.DivIcon(\n            html=f&quot;&quot;&quot;&quot;\n            &lt;div style=&quot;text-align: center;&quot;&gt;\n                &lt;div style=&quot;font-size: 12pt; font-weight: bold; color: black; background-color: white; border-radius: 50%;                 width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;&quot;&gt;\n                {idx}\n                &lt;\/div&gt;\n                &lt;div style=&quot;font-size: 10pt; font-weight: bold; color: navy; margin-top: 10px;&quot;&gt;\n                {\u5730\u70b9\u540d\u79f0\uff5d\n                &lt;\/div&gt;\n            &lt;\/div&gt;&quot;&quot;&quot;\n        )\n    ).add_to(m)\n\n# \u6dfb\u52a0\u8def\u7ebf\u548c\u8ddd\u79bb\/\u65f6\u95f4\u4fe1\u606f\nfor (loc1, loc2) in ordered_locations\uff1a\n    # folium.PolyLine()\uff1a\u5728\u4e24\u70b9\u4e4b\u95f4\u753b\u4e00\u6761\u76f4\u7ebf\n    # color\uff1a\u76f4\u7ebf\u7684\u989c\u8272\uff1bweight\uff1a\u76f4\u7ebf\u7684\u7c97\u7ec6\uff1bopacity\uff1a\u76f4\u7ebf\u7684\u900f\u660e\u5ea6\n    folium.PolyLine([simplified_locations[loc1], simplified_locations[loc2]], color=&quot;blue&quot;, weight=2.5, opacity=1).add_to(m)\n\n    # \u83b7\u53d6\u8ddd\u79bb\u548c\u65f6\u95f4\u4fe1\u606f\n    distance_km, time_min = simplified_distances_and_times[(loc1, loc2)] \u8ddd\u79bb\u548c\u65f6\u95f4\u4fe1\u606f\n    # \u8ba1\u7b97\u4e24\u70b9\u7684\u4e2d\u70b9\u5750\u6807\n    mid_point = [(simplified_locations[loc1][0] + simplified_locations[loc2][0]) \/ 2\u3001\n                 (simplified_locations[loc1][1] + simplified_locations[loc2][1]) \/ 2\uff3d\n    \u5728 # \u7684\u4e2d\u70b9\u6dfb\u52a0\u5305\u542b\u8ddd\u79bb\u548c\u65f6\u95f4\u4fe1\u606f\u7684\u6807\u8bb0\n    folium.Marker(\n        mid_point\u3001\n        icon=folium.DivIcon(\n            html=f'&lt;div style=&quot;font-size: 10pt; font-weight: bold; color: red;&quot;&gt;{\u8ddd\u79bb_\u516c\u91cc}\u516c\u91cc\uff0c{\u65f6\u95f4_\u5206\u949f}\u5206\u949f&lt;\/div&gt;',\n        )\n    ).add_to(m)\n\n# \u5c06\u5730\u56fe\u4fdd\u5b58\u4e3a HTML\n# os.path.join()\uff1a\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7279\u6709\u7684\u8def\u5f84\u5206\u9694\u7b26\u751f\u6210\u6587\u4ef6\u8def\u5f84\nfinal_corrected_map_path = os.path.join(result_dir, 'ny_business_trip_final_corrected_map_with_distances.html')\nm.save(final_corrected_map_path) # \u5c06\u751f\u6210\u7684\u5730\u56fe\u4fdd\u5b58\u4e3a HTML \u6587\u4ef6\n\nprint(f &quot;Map saved to: {final_corrected_map_path}&quot;) # \u6253\u5370\u4fdd\u5b58\u6587\u4ef6\u7684\u8def\u5f84<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u5f53\u60a8\u8ba1\u5212\u53bb\u4e00\u4e2a\u4ece\u672a\u53bb\u8fc7\u7684\u5730\u65b9\u65c5\u884c\u65f6\uff0c\u5f88\u60f3\u67e5\u770b\u4e00\u4e0b\u6574\u4e2a\u8def\u7ebf......<\/p>","protected":false},"author":3,"featured_media":2388,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[3],"tags":[195,194,196,193],"class_list":["post-2376","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-coding","tag-folium-","tag-python-map-visualization","tag-196","tag-193"],"taxonomy_info":{"category":[{"value":3,"label":"\ud30c\uc774\uc36c(Python)"}],"post_tag":[{"value":195,"label":"Folium \ud29c\ud1a0\ub9ac\uc5bc"},{"value":194,"label":"Python Map Visualization"},{"value":196,"label":"\ub274\uc695 \uc5ec\ud589 \uc9c0\ub3c4"},{"value":193,"label":"\uc5ec\ud589 \uacbd\ub85c \uc2dc\uac01\ud654"}]},"featured_image_src_large":["https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/08\/\ud30c\uc774\uc36c-\uc9c0\ub3c4-\uc2dc\uac01\ud654-\uc378\ub124\uc77c-600x600.webp",600,600,true],"author_info":{"display_name":"TERE","author_link":"https:\/\/secondlife.lol\/zh\/author\/tere\/"},"comment_info":0,"category_info":[{"term_id":3,"name":"\ud30c\uc774\uc36c(Python)","slug":"python-coding","term_group":0,"term_taxonomy_id":3,"taxonomy":"category","description":"","parent":20,"count":116,"filter":"raw","cat_ID":3,"category_count":116,"category_description":"","cat_name":"\ud30c\uc774\uc36c(Python)","category_nicename":"python-coding","category_parent":20}],"tag_info":[{"term_id":195,"name":"Folium \ud29c\ud1a0\ub9ac\uc5bc","slug":"folium-%ed%8a%9c%ed%86%a0%eb%a6%ac%ec%96%bc","term_group":0,"term_taxonomy_id":195,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":194,"name":"Python Map Visualization","slug":"python-map-visualization","term_group":0,"term_taxonomy_id":194,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":196,"name":"\ub274\uc695 \uc5ec\ud589 \uc9c0\ub3c4","slug":"%eb%89%b4%ec%9a%95-%ec%97%ac%ed%96%89-%ec%a7%80%eb%8f%84","term_group":0,"term_taxonomy_id":196,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":193,"name":"\uc5ec\ud589 \uacbd\ub85c \uc2dc\uac01\ud654","slug":"%ec%97%ac%ed%96%89-%ea%b2%bd%eb%a1%9c-%ec%8b%9c%ea%b0%81%ed%99%94","term_group":0,"term_taxonomy_id":193,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/posts\/2376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/comments?post=2376"}],"version-history":[{"count":5,"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/posts\/2376\/revisions"}],"predecessor-version":[{"id":2389,"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/posts\/2376\/revisions\/2389"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/media\/2388"}],"wp:attachment":[{"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/media?parent=2376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/categories?post=2376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/secondlife.lol\/zh\/wp-json\/wp\/v2\/tags?post=2376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}