我已将谷歌地图按钮放置在路线视图控制器上用于谷歌地图。我已经生成了pod文件并创建了GoogleMapVC类.GoogleMapVC类仅显示序列中的最后一个坐标(即最后一个顺序是 self.coordinates(a:33.720805,b:73.057037,c:" ccc")仅显示)。我想显示GoogleMapVC类中提到的所有坐标。如何显示所有坐标? 这是我的GoogleMapVC课程。您可以从此链接下载示例项目进行更正 https://www.dropbox.com/s/gv0b7w8dir9mxl3/IOS9DrawRouteMapKitTutorial.zip?dl=0
import UIKit
import GoogleMaps
class GoogleMapVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title="Google Map"
self.coordinates(a:33.718619,b:73.075135,c:"aaa")
self.coordinates(a:33.712162,b:73.049859,c:"bbb")
self.coordinates(a:33.720805,b:73.057037,c:"ccc")
}
func coordinates(a:Double ,b:Double, c:String) {
let camera = GMSCameraPosition.camera(withLatitude:a,longitude:b, zoom:14)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera:camera)
let marker = GMSMarker()
marker.position = camera.target
marker.snippet = c
marker.appearAnimation = kGMSMarkerAnimationPop
marker.map = mapView
self.view = mapView
}
}
答案 0 :(得分:0)
很明显,mapView只显示最后设置的坐标,因为你设置了3次自我坐标,这意味着每次更新值。
因此,如果您想显示多个点,请考虑将所有不同的坐标添加到数组中,并修改您的方法
let locations = [
["latitude": 33.718619, "longitude": 73.075135],
["latitude": 33.712162, "longitude": 73.049859],
["latitude": 33.720805, "longitude": 73.057037]
]
for location in locations {
let annotation = MKPointAnnotation()
annotation.title = location["title"] as? String
annotation.coordinate = CLLocationCoordinate2D(latitude: location["latitude"] as! Double, longitude: location["longitude"] as! Double)
mapView.addAnnotation(annotation)
}
答案 1 :(得分:0)
试试这个
import UIKit
import GoogleMaps
class GoogleMapVC: UIViewController {
var mapView : GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
self.title="Google Map"
let camera = GMSCameraPosition.camera(withLatitude: 33.718619,longitude: 73.075135, zoom:8)
mapView = GMSMapView.map(withFrame: CGRect.zero, camera:camera)
self.view = mapView
self.coordinates(a:33.718619,b:73.075135,c:"aaa")
self.coordinates(a:33.712162,b:73.049859,c:"bbb")
self.coordinates(a:33.720805,b:73.057037,c:"ccc")
}
func coordinates(a:Double ,b:Double, c:String) {
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: a, longitude: b)
marker.snippet = c
marker.appearAnimation = kGMSMarkerAnimationPop
marker.map = mapView
}
}
这将显示更高的视图,您应该看到地图上的所有标记。
答案 2 :(得分:-1)
如果您只想在地图上显示一次点,则应该只使用self.coordinates(a:33.720805,b:73.057037,c:"ccc")
。