ios - 如何解析谷歌地图的纬度和经度?

标签 ios swift google-maps google-maps-sdk-ios

我的目标是解析谷歌地图的纬度和经度,假设mapViewGMSMapView类的 View 对象,并且我已经初始化了它。

override func viewDidLoad() {
    super.viewDidLoad()
    locationManager.delegate = self
       // Ask for Authorisation from the User.
    self.locationManager.requestAlwaysAuthorization()
    // For use in foreground
    self.locationManager.requestWhenInUseAuthorization()

    // This is where I will parse the lat and long
    var coordinate: CLLocationCoordinate2D
    coordinate = CLLocationCoordinate2D(latitude: 3.203119, longitude: 101.7276145)
    mapView.projection.containsCoordinate(coordinate)
}

每当我运行它时,它都不会显示自定义坐标的标记

最佳答案

let camera = GMSCameraPosition.cameraWithLatitude(yourLatitude,
                                                      longitude: yourLongitude, zoom: 15)
    mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
    mapView.myLocationEnabled = true
    mapView.delegate = self
    mapView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
    self.view.addSubview(mapView)



    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake(yourLatitude, yourLongitude)
    marker.title = strTitleOfMarker
    marker.snippet = strSubTitleOfMarker
    marker.map = mapView



// Add this to .plist file
<key>NSLocationAlwaysUsageDescription</key>
<string>Access your location</string>

关于ios - 如何解析谷歌地图的纬度和经度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37630002/

相关文章:

ios - 调整 AVPlayer 大小时的自动布局问题

xcode - Swift 编译器错误 : Use of undeclared type 'EKEventStore'

ios - 在 UIView 中需要一个用于 SnapKit 约束的完成 block

JavaScript 对象继承

ios - Fyber 奖励视频和优惠墙 iOS

ios - 如何在不重新加载visibleCell的情况下重新加载collectionView上的数据

ios - iPhone SDK : what is the difference between loadView and viewDidLoad?

ios - 使用现有数组中的字典创建一个新数组(提取特定的键值路径)

google-maps - 在谷歌地图上显示来自谷歌电子表格的数据

android - 谷歌地图 setClustering(ClusteringSettings) 方法未解析