首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >屏幕不缩放到右坐标-快速谷歌地图api

屏幕不缩放到右坐标-快速谷歌地图api
EN

Stack Overflow用户
提问于 2016-04-16 07:48:12
回答 1查看 1.7K关注 0票数 0

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

代码语言:javascript
复制
import UIKit
import GoogleMaps
import MapKit

class LocationItemViewController: UIViewController,GMSMapViewDelegate, CLLocationManagerDelegate {

@IBOutlet weak var lblInfo: UILabel!    
@IBOutlet weak var lblTitle: UILabel!
@IBOutlet weak var viewMap: UIView!
@IBOutlet weak var googleMapView: GMSMapView!


override func viewDidLoad() {

    super.viewDidLoad()     
    let latitude = (String(format:"%.02f", locationItem.itemLatitude ) as NSString).doubleValue
    let longgitude = (String(format:"%.02f", locationItem.itemLongitude) as NSString).doubleValue
    let camera = GMSCameraPosition.cameraWithLatitude(latitude,longitude: longgitude, zoom: 7)

    let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
    mapView.myLocationEnabled = true
    self.googleMapView = mapView
    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake((locationItem.itemLatitude as NSString).doubleValue, (locationItem.itemLongitude as NSString).doubleValue)
    marker.title = "somelocation"
    marker.snippet = "anywhere"
    marker.map = mapView
    lblTitle.text = locationItem.itemName
    lblInfo.text = locationItem.itemAddress
}

我在app委托中找到了GMSServices.provideAPIKey("YOUR_API_KEY")

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-16 16:55:33

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

在plist中,您必须添加2个条目并获得用户的许可。

  1. NSLocationWhenInUseUsageDescription
  2. NSLocationAlwaysUsageDescription

有关详细信息,请查看此链接。

iOS 8 CLLocationManagerDelegate methods are never called

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

代码语言:javascript
复制
var mapView:GMSMapView?

现在在你的viewDidLoad

代码语言:javascript
复制
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)

}

这是变焦法

代码语言:javascript
复制
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()
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36661592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档