【发布时间】:2015-10-22 06:34:57
【问题描述】:
您好,我试图将地图放在子视图中,但是当我将谷歌地图放在子视图中时,标记不起作用,GPS 坐标也不起作用
-SWIFT 代码
import UIKit
import GoogleMaps
class HomeViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var mapView: GMSMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
let camera = GMSCameraPosition.cameraWithLatitude(15.4989, longitude: 73.8278, zoom: 6)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
// self.view = mapView
self.view.addSubview(mapView)
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(15.4989, 73.8278)
marker.title = "Panjim"
marker.snippet = "Near Don Bosco,Alphran Plaza"
marker.map?.addSubview(mapView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
提前致谢
【问题讨论】:
-
您使用
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera),这将使mapView的大小为零。此外,就像@mixth 建议的那样,您应该改用marker.map = mapView,将标记添加到您的mapView。 -
如果我喜欢它就会出现在视野之外
标签: ios swift google-maps