当前位置 : 主页 > 手机开发 > ios >

标记未在子视图IOS SWIFT中的谷歌地图中找到

来源:互联网 收集:自由互联 发布时间:2021-06-11
您好我试图将地图放在子视图中但是当我在子视图中放置谷歌地图时它不起作用标记和GPS坐标不起作用 – 使用子视图 – 没有子视图 -SWIFT代码 import UIKitimport GoogleMapsclass HomeViewControll
您好我试图将地图放在子视图中但是当我在子视图中放置谷歌地图时它不起作用标记和GPS坐标不起作用

– 使用子视图
With Sub View

– 没有子视图
Without Sub View

-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)
网友评论