您的
UIGraphics绘制方法可能不正确,您可以尝试以下代码从文本制作新图像:
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, 0, size.width, 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. }}


