我是Swift的新手。我強麥得到谷歌地圖2個標記:使用Google iOS SDK創建多個標記
import UIKit
import GoogleMaps
class ViewController: UIViewController {
// You don't need to modify the default init(nibName:bundle:) method.
override func loadView() {
let camera = GMSCameraPosition.cameraWithLatitude(37.0902, longitude: -95.7129, zoom: 3.0)
let mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
mapView.myLocationEnabled = true
view = mapView
let state_marker = GMSMarker()
state_marker.position = CLLocationCoordinate2D(latitude: 61.370716, longitude: -152.404419)
state_marker.title = "Alaska"
state_marker.snippet = "Hey, this is Alaska"
state_marker.map = mapView
let state_marker1 = GMSMarker()
state_marker1.position = CLLocationCoordinate2D(latitude: 32.806671, longitude: -86.791130)
state_marker1.title = "Alabama"
state_marker1.snippet = "Hey, this is Alabama"
state_marker1.map = mapView
}
}
我需要添加51個多種標誌物不同的緯度和經度與不同的標題和摘要各狀態。
我可能只是複製這個塊51次,但有沒有一種方法來優化此代碼?
markerDict會做什麼? – dang
如果你想稍後訪問標記(你可能會這樣做),你可以使用字典來訪問它:'markerDict [「Alaska」]'。如果您確定不會訪問標記,請忽略它。 @dang – Sweeper
完美,謝謝! – dang