【发布时间】:2018-03-13 14:32:32
【问题描述】:
我有数组中的纬度和经度数。我想在谷歌地图中显示多个标记。我对此有疑问。这是我的代码。
@IBOutlet weak var viewMap: UIView!
let locationManager = CLLocationManager()
var mapView = GMSMapView()
var cameraPosition = GMSCameraPosition()
fileprivate func loadData() {
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
showCurrentLocationOnMap()
}
func showCurrentLocationOnMap(){
mapView.settings.myLocationButton = true
mapView.isMyLocationEnabled = true
for data in nearByPlacesArray!{
let camera = GMSCameraPosition.camera(withLatitude: (data.latitude)!, longitude: (data.longitude)!, zoom: 14.0)
mapView = GMSMapView.map(withFrame: CGRect(x: 0, y: 0, width: self.viewMap.frame.size.width, height: self.viewMap.frame.size.height), camera: camera)
let location = CLLocationCoordinate2D(latitude: data.latitude!, longitude: data.longitude!)
print("location: \(location)")
let marker = GMSMarker()
marker.position = location
marker.snippet = data.name!
marker.map = mapView
}
self.viewMap.addSubview(mapView)
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.showCurrentLocationOnMap()
self.locationManager.stopUpdatingLocation()
}
我无法使用此代码在地图视图中显示多个标记。地图中只显示一个与数组的最后一个索引相关的标记。请有人帮助我。谢谢
【问题讨论】:
标签: swift google-maps marker