我目前正在尝试从MapKit实现MKSnapshotter。我想使用苹果地图在mapview(街景视图)中找到要查找的位置的快照。
这是我到目前为止的代码:
var options: MKMapSnapshotOptions = MKMapSnapshotOptions();
options.region = self.attractionDetailMap.region;
options.size = self.attractionDetailMap.frame.size;
options.scale = UIScreen.mainScreen().scale;
var fileURL:NSURL = NSURL(fileURLWithPath: "path/to/snapshot.png")!;
var snapshotter:MKMapSnapshotter = MKMapSnapshotter();
snapshotter.startWithCompletionHandler { (snapshot:MKMapSnapshot!, error:NSError!) -> Void in
if(error != nil) {
println("error: " + error.localizedDescription);
return;
}
var image:UIImage = snapshot.image;
var data:NSData = UIImagePNGRepresentation(image);
data.writeToURL(fileURL, atomically: true);
var pin:MKAnnotationView = MKAnnotationView();
UIGraphicsBeginImageContextWithOptions(image.size, true, image.scale);
image.drawAtPoint(CGPointMake(0.0, 0.0));
var rect:CGRect = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
for annotation in self.attractionDetailMap.annotations {
var point:CGPoint = snapshot.pointForCoordinate(annotation.coordinate);
}
}
当我尝试确定一个点(变量point:CGPoint = snapshot.pointForCoordinate(annotation.coordinate);)时,错误:“ coordinate”不可用:iOS7及更早版本中不推荐使用的API在Swift中不可用。
基本上,由于没有太多关于如何快速使用MKSnapshotter的教程/指南,因此,如果我能很快看到MKSNapshotter的标准结构,将不胜感激。我觉得自己走在正确的道路上,但是我被困在最后一行代码中,坦率地说,这甚至行不通。
谢谢!
您需要转换注释以更正类型。
for annotation in self.attractionDetailMap.annotations as! [MKAnnotation] {
let point = snapshot.pointForCoordinate(annotation.coordinate)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句