标记不在子视图IOS SWIFT中的谷歌地图中定位 [英] Marker not locating in google map in subview IOS SWIFT

查看:135
本文介绍了标记不在子视图IOS SWIFT中的谷歌地图中定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

- 使用子视图



- 没有子视图
a>

-SWIFT CODE

 导入UIKit 
导入GoogleMaps

类HomeViewController:UIViewController,CLLocationManagerDelegate {

@IBOutlet弱var mapView:GMSMapView!

让locationManager = CLLocationManager()

重写func viewDidLoad(){
super.viewDidLoad()
locationManager.delegate = self
locationManagerManager.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 =临近Don Bosco,Alphran Plaza
marker.map?.addSubview(mapView)

}

覆盖func didReceiveMemoryWarning(){
super.didReceiveMemoryWarnin g()
//处理任何可以重新创建的资源。
}

}

预先致谢

以下是添加标记的解决方案

  let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(lat,long)
marker.appearAnimation = kGMSMarkerAnimationPop
marker.title =Marker/ /标记标题在这里
marker.snippet =点击↱导航按钮开始导航。
marker.infoWindowAnchor = CGPoint(x:0.5,y:0)
marker.icon = UIImage(named:marker)//在这里设置标记图标
marker.map = self。 mapView // Mapview here

Animate Camera to position

  let camera = GMSCameraPosition.camera(withLatitude:15.4989,longitude:73.8278,zoom:17)
mapView.animate(to:camera)


Hello i was trying to put map in subview but when i put google map in sub view it doesn't work marker and GPS Coordinates don't work

-With Sub View

-Without Sub View

-SWIFT CODE

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.
    }

}

Thanks in advance

解决方案

Here is the solution to add marker

            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

Animate Camera to position

    let camera = GMSCameraPosition.camera(withLatitude: 15.4989, longitude: 73.8278, zoom: 17)
    mapView.animate(to: camera)

这篇关于标记不在子视图IOS SWIFT中的谷歌地图中定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆