这是当前的代码,在进行修改后,它不再在澳大利亚悉尼地图上显示标记
class LocateVC:UIViewController {
@IBOutlet weak var mapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
//override func loadView() {
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.camera(withLatitude: -33.86 , longitude: 151.20, zoom: 6.0)
let mapView = GMSMapView.map(withFrame: self.mapView.bounds, camera: camera)
self.mapView = mapView
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
}
}
输出
答案 0 :(得分:0)
您正在将mapview
设为view
的主ViewController
所以改变这两行
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView
。通过强>
let mapView = GMSMapView.map(withFrame: self.mapView.bounds, camera: camera)
self.mapView = mapView
答案 1 :(得分:0)
@Nirav的答案几乎就在那里
这里我做了什么:
import UIKit
import GoogleMaps
class AddressMapController: UIViewController {
@IBOutlet weak var map123: GMSMapView! // this is linked to a UIView in storyboard
var currentLocation: CLLocation! //this is passed from the main controller
override func viewDidLoad() {
super.viewDidLoad()
let lat = currentLocation.coordinate.latitude
let long = currentLocation.coordinate.longitude
let camera = GMSCameraPosition.camera(withLatitude: lat , longitude: long, zoom: 12)
// Creates a marker in the center of the map.
let currentLocation_Marker = GMSMarker()
currentLocation_Marker.position = CLLocationCoordinate2D(latitude: lat, longitude: long)
currentLocation_Marker.title = "My Current Location"
currentLocation_Marker.snippet = "I am here now"
currentLocation_Marker.map = map123
self.map123.camera = camera
}
}
希望它能在未来帮助某人