Kiểu bản đồ mới sắp xuất hiện trên Nền tảng Google Maps. Bản cập nhật này để tạo kiểu bản đồ bao gồm một bảng màu mặc định mới và các cải tiến về trải nghiệm bản đồ cũng như khả năng hữu dụng. Tất cả kiểu bản đồ sẽ được cập nhật tự động vào tháng 3 năm 2025. Để biết thêm thông tin về phạm vi cung cấp và cách chọn tham gia sớm hơn, hãy xem bài viết Kiểu bản đồ mới cho Nền tảng Google Maps.
Trang này cho bạn biết cách hiển thị dữ liệu địa lý trong GeoJSON
định dạng, sử dụng GMUGeoJSONParser, trong
kết hợp với GMUGeometryRenderer. GeoJSON là một định dạng tệp phổ biến
để kết xuất dữ liệu địa lý như điểm, đường và đa giác.
Để xem mã mẫu đầy đủ, hãy xem các ứng dụng mẫu
bật
GitHub.
Hiển thị dữ liệu GeoJSON
Để kết xuất dữ liệu GeoJSON trên bản đồ, hãy tạo GMUGeoJSONParser với
đường dẫn đến tài nguyên GeoJSON (GeoJSON_sample.kml trong
ví dụ). Sau đó, hãy tạo một GMUGeometryRenderer, truyền tham số
Thực thể GMUKMLParser. Cuối cùng, hãy gọi
GMUGeometryRenderer.render(). Ví dụ về mã sau đây cho thấy
kết xuất dữ liệu GeoJSON trên bản đồ:
Swift
import GoogleMapsUtils
class GeoJSON {
private var mapView: GMSMapView!
func renderGeoJSON() {
guard let path = Bundle.main.path(forResource: "GeoJSON_sample", ofType: "json") else {
return
}
let url = URL(fileURLWithPath: path)
let geoJsonParser = GMUGeoJSONParser(url: url)
geoJsonParser.parse()
let renderer = GMUGeometryRenderer(map: mapView, geometries: geoJsonParser.features)
renderer.render()
}
}
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2024-09-05 UTC."],[[["This page demonstrates how to render geographic data in GeoJSON format on Google Maps using the `GMUGeoJSONParser` and `GMUGeometryRenderer`."],["GeoJSON is a commonly used format for displaying geographic data like points, lines, and polygons."],["You'll need to set up the Maps SDK for iOS Utility Library before using `GMUGeoJSONParser`."],["The provided code examples show how to render GeoJSON data on a map in both Swift and Objective-C."]]],[]]