您好我试图将地图放在子视图中但是当我在子视图中放置谷歌地图时它不起作用标记和GPS坐标不起作用 – 使用子视图 – 没有子视图 -SWIFT代码 import UIKitimport GoogleMapsclass HomeViewControll
– 使用子视图
– 没有子视图
-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 marker = GMSMarker() marker.position = CLLocationCoordinate2DMake(lat, long) marker.appearAnimation = kGMSMarkerAnimationPop marker.title = "Marker" // Marker title here marker.snippet = "Tap the ↱ Navigate button to start navigating." marker.infoWindowAnchor = CGPoint(x: 0.5, y: 0) marker.icon = UIImage(named: "marker") //Set marker icon here marker.map = self.mapView // Mapview here
动画相机定位
let camera = GMSCameraPosition.camera(withLatitude: 15.4989, longitude: 73.8278, zoom: 17) mapView.animate(to: camera)