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中的谷歌地图中定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!