gpt4 book ai didi

ios - 在 UIView 中正确显示谷歌地图

转载 作者:行者123 更新时间:2023-11-29 00:17:47 25 4
gpt4 key购买 nike

我在 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。当我将 map 附加到 UIViewController 时,我得到了经纬度坐标。当我尝试将 map 附加到 UIView 时,我得到了不同的 map 、缩放级别等,如下图所示。

the maps

如何让 UIView map 正确描绘?附:我尝试了 viewDidLoad 和 viewDidAppear,结果相同。谢谢

最佳答案

您已经为 GMSMapView 创建了一个 IBOutlet

它将为您创建一个 map 实例。因此无需再创建一个 GMSMapView 实例并将其分配给类变量。

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)

self.myMapView.mapType = .terrain

self.myMapView.camera = camera


// 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 = self.myMapView
marker.opacity = 1.0
}

关于ios - 在 UIView 中正确显示谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44845048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com