ios - 与输入相比,谷歌地图显示不同的位置

标签 ios swift google-maps

当允许在主视图上显示时,Google map 可以正常工作。

但是,当我使用新的 Sub 时, map 的位置是错误的,即使纬度和经度值发生变化, map 的位置似乎也没有改变。

代码片段:

 import UIKit
 import GoogleMaps

 class MainVC: UIViewController {


@IBOutlet weak var mapSubView: GMSMapView!

override func viewDidLoad() {

    let camera = GMSCameraPosition.cameraWithLatitude(13.009047, longitude: 77.652949, zoom: 6)
    let mapView = GMSMapView.mapWithFrame(self.mapSubView.bounds, camera: camera)

    mapView.myLocationEnabled = true

    self.mapSubView = mapView


    // Creates a marker in the center of the map.
    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2D(latitude: 13.009047, longitude: 77.652949)
    marker.title = "Bangalore"
    marker.snippet = "India"
    marker.map = mapView
}

}

应用截图: enter image description here

最佳答案

将此行添加到您的代码中:-

 mapSubView.camera = GMSCameraPosition(target: CLLocationCoordinate2D(latitude: 13.009047, longitude: 77.652949), zoom: 15, bearing: 0, viewingAngle: 0)

GoogleMaps camera 只是定义 map 的方向以及属性,例如你想要多少缩放,缩放的目标是什么等等。有关此功能的更多详细信息以及参数是什么在这个函数上代表 CMD+CLICK 去它的文档

编辑: 上面的代码添加了一个新的 GMSMapView,使用 View Controller 中的代码在已经存在的 GMSMapView 之上,该 GMSMapView 使用 IBOutlet 配置

更新代码:

@IBOutlet weak var mapSubView: GMSMapView!

override func viewDidLoad() {


    mapSubView.myLocationEnabled = true
    mapSubView.camera = GMSCameraPosition(target: CLLocationCoordinate2D(latitude: 13.009047, longitude: 77.652949), zoom: 15, bearing: 0, viewingAngle: 0)


    // Creates a marker in the center of the map.
    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2D(latitude: 13.009047, longitude: 77.652949)
    marker.title = "Bangalore"
    marker.snippet = "India"
    marker.map = mapSubView
}

Google map iOS SDK 文档:GMSCameraPosition Class Reference

Google map iOS SDK 文档: GMSMarker Class Reference

关于ios - 与输入相比,谷歌地图显示不同的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39270736/

相关文章:

android - 单击 android 中的标记时如何更改标记颜色?

ios - 使用回调延迟 swift 服务类的输出

ios - 使用 Braintree 支付流程的客户端 IOS 到服务器

swift - 通过点击关闭键盘时丢弃输入

android - map 聚类 - 最大缩放标记仍然聚类

java - NullPointerException Google map API Android 4.4.4

ios - 在哪里放置代码来更改 UIView 的属性

ios - 根据 iPhone 上的内容设置 webview 的动态高度

swift - Swift 中的 localizeWithFormat 和可变参数

swift - 用户与 ios-charts 的交互