我正在使用iOS(Swift)的谷歌地图sdk.
有谁知道如何"当我打开ViewController时,在谷歌地图上显示我的当前位置"?
实际上它就像谷歌地图应用程序.当您打开Google地图时,蓝点将显示您当前的位置.您不需要在第一次按"myLocationButton".
所以这是代码:
import UIKit
import CoreLocation
import GoogleMaps
class GoogleMapsViewer: UIViewController {
@IBOutlet weak var mapView: GMSMapView!
let locationManager = CLLocationManager()
let didFindMyLocation = false
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.cameraWithLatitude(23.931735,longitude: 121.082711, zoom: 7)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
self.view = mapView
// GOOGLE MAPS SDK: BORDER
let mapInsets = UIEdgeInsets(top: 80.0, left: 0.0, bottom: 45.0, right: 0.0)
mapView.padding = mapInsets
locationManager.distanceFilter = 100
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
// GOOGLE MAPS …
Run Code Online (Sandbox Code Playgroud)