如何在swift中制作可点击的谷歌地图贴片
我正在ios9中使用googlemapssdk,目前我正在地图上用不同的颜色显示平铺层,这些颜色代表一个值。我想添加点击一个磁贴并显示有关该磁贴的信息的功能,例如该磁贴的实际值。我在网上查看了一下,发现的唯一一件事是为每个磁贴制作透明的标记,然后为每个标记编写一个处理程序来显示值,但我认为必须有一种更有效的方法来做到这一点。有人能把我引向正确的方向吗?谢谢如何在swift中制作可点击的谷歌地图贴片,swift,google-maps,ios9,google-maps-sdk-ios,Swift,Google Maps,Ios9,Google Maps Sdk Ios,我正在ios9中使用googlemapssdk,目前我正在地图上用不同的颜色显示平铺层,这些颜色代表一个值。我想添加点击一个磁贴并显示有关该磁贴的信息的功能,例如该磁贴的实际值。我在网上查看了一下,发现的唯一一件事是为每个磁贴制作透明的标记,然后为每个标记编写一个处理程序来显示值,但我认为必须有一种更有效的方法来做到这一点。有人能把我引向正确的方向吗?谢谢 class MyMapView: UIView{ var myMap: GMSMapView! var closestPoint: CLL
class MyMapView: UIView{
var myMap: GMSMapView!
var closestPoint: CLLocationCoordinate2D!
required init?(coder aDecoder: NSCoder) {
fatalError("This class does not support NSCoding")
}
init(closestPoint: CLLocationCoordinate2D!){
super.init(frame: CGRectZero)
self.backgroundColor = UIVariables.blackOpaque
self.closestPoint = closestPoint
var camera = GMSCameraPosition.cameraWithLatitude(AppVariables.location2D!.latitude, longitude: AppVariables.location2D!.longitude, zoom: 6)
self.myMap = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
self.myMap.mapType = GoogleMaps.kGMSTypeSatellite
delay(seconds: 0.5) { () -> () in
let path = GMSMutablePath()
path.addCoordinate(self.closestPoint!)
path.addCoordinate(AppVariables.location2D!)
let bounds = GMSCoordinateBounds(path: path)
self.myMap.moveCamera(GMSCameraUpdate.fitBounds(bounds, withPadding: 50.0))
let layer = MyMapTileLayer()
layer.map = self.myMap
}
self.myMap.translatesAutoresizingMaskIntoConstraints = false
//self.frame = CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 400)
self.addSubview(self.myMap)
let viewsDictionary = ["map": self.myMap]
let metricDictionary = ["width": self.frame.size.width/2]
let view_constraint_V1:Array = NSLayoutConstraint.constraintsWithVisualFormat("V:|[map]-15-|", options: NSLayoutFormatOptions.AlignAllLeading, metrics: metricDictionary, views: viewsDictionary)
let view_constraint_H1:Array = NSLayoutConstraint.constraintsWithVisualFormat("H:|-10-[map]-10-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: metricDictionary, views: viewsDictionary)
self.addConstraints(view_constraint_V1)
self.addConstraints(view_constraint_H1)
}
func delay(seconds seconds: Double, completion:()->()) {
let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64( Double(NSEC_PER_SEC) * seconds ))
dispatch_after(popTime, dispatch_get_main_queue()) {
completion()
}
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
class MyTileLayer: GMSTileLayer{
var webService = WebService()
override func requestTileForX(x: UInt, y: UInt, zoom: UInt, receiver: GMSTileReceiver!) {
webService.getTiles(x, y: y, z: zoom, completion: { (result) -> Void in
receiver.receiveTileWithX(x, y: y, zoom: zoom, image: UIImage(data: result))
})
}
}
你能分享你的代码吗!,方砖是什么意思?infowindows/Marker使用可能有用的代码进行了更新,但我所问的是非常通用的,所以我的代码应该并不重要。当我说方形瓷砖时,我的意思是谷歌地图瓷砖层点击手势问题,我在谷歌地图上使用手势动作时遇到了这个问题,所以我使用了触摸开始功能来进行动作。否则,我们将尝试以下操作:mapView.settings.ConsumesGeturesInView=TrueInterest。。我找到了一个函数,该函数在地图上为您提供坐标,用户点击了:func mapView(mapView:GMSMapView!,didTapAtCoordinate坐标:CLLocationCoordinate2D)。我想我可以用这个。谢谢你的帮助!点击goole map时将调用didTapAtCoordinate func。