gpt4 book ai didi

ios - 使用 MapboxStatic api 时,标记叠加层必须是 png、jpg 或 webp

转载 作者:行者123 更新时间:2023-11-28 23:20:23 25 4
gpt4 key购买 nike

这就是我创建标记并将其添加到叠加层数组的方式:

let text = "1"
let url = URL(string: "http://texttopng.azurewebsites.net/Home/TextToPng?text=\(text)")!
let marker = CustomMarker(coordinate: label.location.coordinate, url: url)

但是当我尝试拍摄快照时:

_ = Snapshot(options: options, accessToken: nil).image { image, error in
//error: Error Domain=MBStaticErrorDomain Code=-1 "Marker overlays must be png, jpg, or webp" UserInfo={NSLocalizedFailureReason=Marker overlays must be png, jpg, or webp}
}

为什么会这样?

这是我试过的:

let image = UIImage(named: "icon-card")!
let png = UIImagePNGRepresentation(image)!
let newurl = png.write(withName: "\(text).png")
let marker = CustomMarker(coordinate: label.location.coordinate, url: newurl)

extension Data {
func write(withName name: String) -> URL {

let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(name)

try! write(to: url, options: .atomicWrite)

return url
}
}

enter image description here

最佳答案

我想分享我的代码,它可以正常工作:

let text = "Hello"
let urlWithText = URL(string: "http://texttopng.azurewebsites.net/Home/TextToPng?text=\(text)")!
let marker = CustomMarker(coordinate: CLLocationCoordinate2D(latitude: 53.705912, longitude: 23.840836), url: urlWithText)

let camera = SnapshotCamera(
lookingAtCenter: CLLocationCoordinate2D(latitude: 53.705912, longitude: 23.840836),
zoomLevel: 12)
let options = SnapshotOptions(
styleURL: URL(string: "mapbox://styles/mapbox/satellite-streets-v9")!,
camera: camera,
size: CGSize(width: 400, height: 200))
options.overlays = [marker]

_ = Snapshot(options: options, accessToken: nil).image { image, error in
_ = image?.jpegData(compressionQuality: 1.0)?.write(withName: "my_snapshot.jpg")
}

我使用你的扩展名 for Data 来保存jpg 文件

extension Data {
func write(withName name: String) -> URL {
let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(name)
print(url.path)
try! write(to: url, options: .atomicWrite)
return url
}
}

结果我得到了这样的截图: enter image description here我想您可以尝试使用我的代码或其中的一部分并检查您的环境。我使用 MapboxStatic.swift (0.11.0) Mapbox pod

关于ios - 使用 MapboxStatic api 时,标记叠加层必须是 png、jpg 或 webp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59718486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com