【发布时间】:2017-06-30 11:09:18
【问题描述】:
我在 iOS 上使用谷歌地图。
这是我的代码:
import UIKit
import GoogleMaps
ViewController: UIViewController {
@IBOutlet weak var myMapView: GMSMapView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
let camera = GMSCameraPosition.camera(withLatitude: +31.75097946, longitude: +35.23694368, zoom: 17.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
//mapView.isMyLocationEnabled = true
mapView.mapType = .terrain
self.view = mapView
//self.myMapView = mapView
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: +31.75097946, longitude: +35.23694368)
marker.title = "Eden VidanPeled"
//marker.snippet = "Australia"
marker.map = mapView
marker.opacity = 1.0
}
在 Interface Builder 中,我有一个带有 GMSMapView 类的 UIView。当我将地图附加到 UIViewController 时,我得到了经纬度坐标。当我尝试将地图添加到 UIView 时,我得到了不同的地图、缩放级别等, 如下图所示。
如何让 UIView 地图正确描绘? p.s.我尝试了 viewDidLoad 和 viewDidAppear ,结果相同。 谢谢
【问题讨论】:
-
像使用 addsubview 函数一样将地图视图添加到您的视图中
标签: ios google-maps swift3 xcode8