大佬教程收集整理的这篇文章主要介绍了为iOS swift的谷歌地图中的多边形添加文本标签,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是困扰我的代码部分:
func updateUIMap(){ var str = "Hello" var data = str.dataUsingEncoding(NSUTF8StringEncoding,allowLossyConversion: truE) var drawText = NSString(data: data!,encoding: NSUTF8StringEncoding) let size = CGSize(width: 24.0,height: 24.0) var inImage = UIImage() var textColor: UIColor = UIColor.blackColor() var textFont: UIFont = UIFont(name: "Helvetica Bold",size: 12)! UIGraphicsBeginImageContext(sizE) let textFontAttributes = [ NSFontAttributename: textFont,NSForegroundColorAttributename: textColor,] inImage.drawInRect(CGRectMake(0,size.width,size.height)) var rect: CGRect = CGRectMake(24,24,size.height) drawText.drawInRect(rect,withAttributes: textFontAttributes) var newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() var overlay = GMSGroundOverlay(position: myposition,icon: newImage,zoomLevel:20) overlay.bearing = 0 overlay.map = self.mapView }
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() super.viewDidLoad() let camera = GMSCameraPosition.cameraWithLatitude(40.712216,longitude: -74.22655,zoom: 10) let mapView = GMsmapView.mapWithFrame(CGRectZero,camera: camera) mapView.myLOCATIOnEnabled = true self.view = mapView addGroundOverlay(camera.target) } func newImage(text: String,size: CGSizE) -> UIImage { let data = text.dataUsingEncoding(NSUTF8StringEncoding,allowLossyConversion: truE) let drawText = NSString(data: data!,encoding: NSUTF8StringEncoding) let textFontAttributes = [ NSFontAttributename: UIFont(name: "Helvetica Bold",size: 20)!,NSForegroundColorAttributename: UIColor.redColor(),] UIGraphicsBeginImageContextWithOptions(size,false,0) drawText?.drawInRect(CGRectMake(0,size.height),withAttributes: textFontAttributes) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage } func addGroundOverlay(position: CLLOCATIOnCoordinate2D) { let overlay = GMSGroundOverlay(position: position,icon: newImage("Hello StackOverflow",size: CGSizeMake(150.0,150.0)),zoomLevel: 10) overlay.bearing = 0 overlay.map = (self.view as! GMsmapView) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
以上是大佬教程为你收集整理的为iOS swift的谷歌地图中的多边形添加文本标签全部内容,希望文章能够帮你解决为iOS swift的谷歌地图中的多边形添加文本标签所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。