Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么';难道我的谷歌地图应用程序没有打印出坐标吗?_Ios_Swift_Google Maps - Fatal编程技术网

Ios 为什么';难道我的谷歌地图应用程序没有打印出坐标吗?

Ios 为什么';难道我的谷歌地图应用程序没有打印出坐标吗?,ios,swift,google-maps,Ios,Swift,Google Maps,我有下面的代码,如果我编译它不工作:如果我改变缩放值,并重新编译它,它就像“没有改变”。此外,当我点击时,打印功能不会打印任何内容。可能是什么问题 import UIKit import GoogleMaps import MapKit class ViewController: UIViewController, GMSMapViewDelegate, UIAlertViewDelegate { @IBOutlet weak var mapView: GMSMapView! var mark

我有下面的代码,如果我编译它不工作:如果我改变缩放值,并重新编译它,它就像“没有改变”。此外,当我点击时,打印功能不会打印任何内容。可能是什么问题

import UIKit
import GoogleMaps
import MapKit

class ViewController: UIViewController, GMSMapViewDelegate, UIAlertViewDelegate {
@IBOutlet weak var mapView: GMSMapView!
var markersArray: Array<CLLocationCoordinate2D> = []

override func viewDidLoad() {
//set default position of the mapView
let camera = GMSCameraPosition.camera(withLatitude: 1.285, longitude: 10.848, zoom: 10)
let mapView = GMSMapView.map(withFrame: self.view.bounds, camera:camera)
//mapView.mapType = kGMSTypeSatellite - use of unresolved identifier 'kGMSTypeSatellite'
mapView.isMyLocationEnabled = true
mapView.settings.compassButton = true
mapView.settings.myLocationButton = true
mapView.camera = camera
mapView.delegate = self
}

func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D){
var lat : String = coordinate.latitude.description
var lng : String = coordinate.longitude.description
markersArray.append(coordinate)
print(markersArray)
print(lat)
print(lng)
    print(coordinate.latitude)
    print(coordinate.longitude)
}
导入UIKit
导入谷歌地图
导入地图套件
类ViewController:UIViewController、GMSMapViewDelegate、UIAlertViewDelegate{
@IBV映射视图:GMSMapView!
var-markersArray:Array=[]
重写func viewDidLoad(){
//设置地图视图的默认位置
让相机=GMSCameraPosition.相机(纬度:1.285,经度:10.848,变焦:10)
设mapView=GMSMapView.map(带边框:self.view.bounds,相机:相机)
//mapView.mapType=kGMSTypeSatellite-使用未解析的标识符“kGMSTypeSatellite”
mapView.isMyLocationEnabled=true
mapView.settings.compassButton=true
mapView.settings.myLocationButton=true
mapView.camera=camera
mapView.delegate=self
}
func地图视图(地图视图:GMSMapView,didTapAt坐标:CLLocationCoordinate2D){
var lat:String=coordinate.latitude.description
变量lng:String=coordinate.longitude.description
markersArray.append(坐标)
打印(markersArray)
打印(lat)
印刷品(液化天然气)
打印(坐标纬度)
打印(坐标经度)
}

我认为您的问题在于您正在创建第二个地图视图:

let mapView = GMSMapView.map(withFrame: self.view.bounds, camera:camera)
并将其委托设置为self。您从不将此地图添加到视图中。您看到和触摸的地图视图来自您的故事板,您有一个出口:

@IBOutlet weak var mapView: GMSMapView!
这是不同的。您创建了一个具有相同名称的局部变量。您从未设置此插座的委托。只需设置插座的相机位置,而不是创建新的地图视图:

override func viewDidLoad() {
  //set default position of the mapView
  let camera = GMSCameraPosition.camera(withLatitude: 1.285, longitude: 10.848, zoom: 10)
  mapView.position = camera
  mapView.isMyLocationEnabled = true
  mapView.settings.compassButton = true
  mapView.settings.myLocationButton = true
  mapView.camera = camera
  mapView.delegate = self
 }
“位置”不是一个属性,所以我不能设置它。尽管它仍然有效,谢谢!