首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >IOS SWIFT子视图中谷歌地图中的标记不定位

IOS SWIFT子视图中谷歌地图中的标记不定位
EN

Stack Overflow用户
提问于 2015-10-22 06:34:57
回答 4查看 2.4K关注 0票数 3

你好,我试图把地图放在子视图中,但是当我把谷歌地图放到子视图中时,它不工作标记,GPS坐标也不起作用

-With子视图

-Without子视图

-SWIFT代码

代码语言:javascript
复制
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.
    }

}

提前感谢

EN

Stack Overflow用户

发布于 2019-06-26 12:19:01

代码语言:javascript
复制
after adding marker you should add some delay with this approach i have added 2 marker with bounds 

DispatchQueue.main.async {
            if self.markerArray.count > 1 {
                var bounds = GMSCoordinateBounds()
                for marker in self.markerArray {
                    marker.map = self.mapView
                    bounds = bounds.includingCoordinate(marker.position)
                }
                self.isMovedTheMap = false
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.9, execute: {
                    self.superTopView.fadeOut()
                    let update = GMSCameraUpdate.fit(bounds, withPadding: 80)
                    self.mapView.animate(with: update)
                })
            }
        }
票数 1
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33274718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档