屏幕没有缩放到右边的坐标 - swift google map api

时间:2016-04-16 07:48:12

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

使用GMSMap获取动态谷歌地图时,地图不显示我给他的当前位置而不缩放地图

Array before sorting:
74  26  1   12  38  81  94  
Array after sorting:
12  1   26  38  74  81  94  

我在app delegate中找到了GMSServices.provideAPIKey(“YOUR_API_KEY”)

1 个答案:

答案 0 :(得分:1)

要显示您当前的位置,您必须执行与Apple地图相同的操作才能访问我们的位置。

在plist中,您必须添加2个条目并获取用户

的许可
  1. NSLocationWhenInUseUsageDescription
  2. NSLocationAlwaysUsageDescription
  3. 点击此链接了解详情<{3}}

    现在关于你的谷歌地图缩放问题

    var mapView:GMSMapView?
    

    现在在viewDidLoad

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        GMSServices.provideAPIKey("YOUR_API_KEY")
    
        //Taking HardCoded lat longs for the time being. These lat longs are of New Delhi, India
        let camera = GMSCameraPosition.cameraWithLatitude(28.6139, longitude: 77.2090, zoom: 10)
        mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
        mapView!.myLocationEnabled = true
        self.view = mapView
    
        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2DMake(28.6139, 77.2090)
        marker.title = "Delhi"
        marker.snippet = "India"
        marker.map = mapView
    
        //As view takes some time to load so I am calling my zoom function after a delay of 1 second. You can use the zoom function code in viewDidAppear too
        //Also this syntax is the latest Swift 2.2 syntax. If you are using the old Swift version, make the changes accordingly for performSelector method
        self.performSelector(#selector(zoom), withObject: nil, afterDelay: 1.0)
    
    }
    

    这是缩放方法

    func zoom() {
    
        CATransaction.begin()
        CATransaction.setValue(1, forKey: kCATransactionAnimationDuration)
    
        // It will animate your camera to the specified lat and long
        let camera = GMSCameraPosition.cameraWithLatitude(28.6139, longitude: 77.2090, zoom: 15)
        mapView!.animateToCameraPosition(camera)
    
        CATransaction.commit()
    }