如何解决通过Mapbox和Swift
我只想在当前用户位置周围画一个5000米的圆圈。
我实现了使用以下代码段绘制半径为100像素的圆。
// MGLShapeSource needs a source - create a MGLPointAnnotation
let pointAnnotation = MGLPointAnnotation()
pointAnnotation.coordinate = CLLocationCoordinate2D(latitude: 49,longitude:9)
// Create a MGLShapeSource
let source = MGLShapeSource(identifier: "circle",shape: pointAnnotation,options: nil)
style.addSource(source)
// Create Circle Layer and style with Options
let circleLayer = MGLCircleStyleLayer(identifier: "circle",source: source)
circleLayer.circleOpacity = NSExpression(forConstantValue: 0)
circleLayer.circleStrokeColor = NSExpression(forConstantValue: UIColor.systemBlue)
circleLayer.circleStrokeWidth = NSExpression(forConstantValue: 1)
// Radius of Circle,for now in pixels.
let meterRadius = 5000 // not used yet
let pixelRadius = 100 // Exchange with formula to convert from meters to Screen Pixels
circleLayer.circleRadius = NSExpression(forConstantValue: pixelRadius)
// Add Layer to Style
style.addLayer(circleLayer)
有人可以通过创建公式来为此计算正确的屏幕像素值来帮助我吗?
我读到以下内容:
let pixelRadius = meterRadius / 0.072 / cos(49 * Double.pi / 180)
但这将忽略Zoomlevel。
有任何提示吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。