我有数组中的纬度和经度。我想在 Google 地图中显示多个标记
I've number of latitude and longitude in array. I want to display multiple markers in Google Map
我在数组中有纬度和经度的数量。我想在 Google 地图中显示多个标记。我是编程新手。
**** 我当前的代码****
导入 UIKit
导入 Google地图
let mapView = GMSMapView()
class ViewController: UIViewController {
let lattitudeary = ["28.5355","28.7041","29.9457","30.0869"]
let longitudeary = ["77.3910","77.1025","78.1642","78.2676"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view = mapView
var marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
// var coords = [[-33.86,151.20],[28.5355,77.1025],[29.9457,78.1642]]
var coords = [[lattitudeary.count],[longitudeary.count]]
for coord in coords {
var marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees(coord[0]), longitude: CLLocationDegrees(coord[1]))
marker.map = mapView
}
}
首先将 Google 地图与您的应用集成
Google Maps iOS SDK
然后尝试在地图上添加标记
Adding a Map with a Marker
var marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
最后使用for循环将多个标记添加到地图中。 Swift Control Flow
var coords = [[-33.86,151.20],[-33.85,151.18],[-33.76,151.14]]
for coord in coords {
var marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: coord[0], longitude: coord[1])
marker.map = mapView
}
我在数组中有纬度和经度的数量。我想在 Google 地图中显示多个标记。我是编程新手。
**** 我当前的代码****
导入 UIKit 导入 Google地图
let mapView = GMSMapView()
class ViewController: UIViewController {
let lattitudeary = ["28.5355","28.7041","29.9457","30.0869"]
let longitudeary = ["77.3910","77.1025","78.1642","78.2676"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view = mapView
var marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
// var coords = [[-33.86,151.20],[28.5355,77.1025],[29.9457,78.1642]]
var coords = [[lattitudeary.count],[longitudeary.count]]
for coord in coords {
var marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees(coord[0]), longitude: CLLocationDegrees(coord[1]))
marker.map = mapView
}
}
首先将 Google 地图与您的应用集成 Google Maps iOS SDK
然后尝试在地图上添加标记 Adding a Map with a Marker
var marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
最后使用for循环将多个标记添加到地图中。 Swift Control Flow
var coords = [[-33.86,151.20],[-33.85,151.18],[-33.76,151.14]]
for coord in coords {
var marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: coord[0], longitude: coord[1])
marker.map = mapView
}