[英]Mapbox custom user location annotation image and position
I want to be able to display a custom image for the user location on a Mapbox map in iOS, and be able to set the current user location from an internal source, rather than using the internal GPS source. 我希望能够在iOS中的Mapbox地图上为用户位置显示自定义图像, 并能够从内部来源而不是内部GPS来源设置当前用户位置。
The built-in user location facility appears to only be able to source location from the Mapbox internal location engine. 内置的用户位置工具似乎只能从Mapbox内部位置引擎获取位置。 I have added a custom annotation to the map, and I can update its position when I get a new location fix, but the motion is jerky (I can pan the map with a camera animation, but not the annotation.) 我已经在地图上添加了自定义注释,当我获得新的位置定位信息时,我可以更新其位置,但是动作很生涩(我可以使用照相机动画平移地图,但不能平移注释。)
Is there any way in the iOS Mapbox SDK to animate changing the location of an annotation? iOS Mapbox SDK中有什么方法可以动画化更改注释的位置?
So this is what I came up with. 这就是我想出的。 In the MGLMapViewDelegate
I use the didFinishRenderingFrame()
callback to update the location, interpolating between the two most recent locations. 在MGLMapViewDelegate
我使用didFinishRenderingFrame()
回调来更新位置,并在两个最新位置之间进行插值。 posAnnotation
is the MGLPointAnnotation
associated with flightMarker
which is an MGLAnnotationView
extended to add a UIImageView
and hold the locations. posAnnotation
是与MGLPointAnnotation
关联的flightMarker
,它是MGLAnnotationView
扩展,可以添加UIImageView
并保存位置。
override fun didFinishRenderingFrame(mapView: MGLMapView, fullyRendered: Boolean) {
val frac = min((CFDate.getCurrentAbsoluteTime() - lastUpdateTimestamp) / lastUpdateInterval, 1.0)
if(flightMarker.location.valid)
posAnnotation.coordinate = flightMarker.interpolatedLocation(frac)
}
override fun viewForAnnotation(mapView: MGLMapView, annotation: MGLAnnotation): MGLAnnotationView? {
return if (annotation == posAnnotation) flightMarker else null
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.