在MKMapView上移动/更新MKOverlay [英] moving/updating MKOverlay on MKMapView

查看:76
本文介绍了在MKMapView上移动/更新MKOverlay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法更新(即移动)已添加到 MKMapView MKOverlay 。删除一个旧的并添加一个新的很糟糕(慢)。

is there a way to update (i.e. moving around) a MKOverlay that is already added to the MKMapView. Removing a old one and adding a new one is terrible (slow).

即我想触发覆盖移动时调用此函数的后台函数屏幕:

i.e i would like to trigger the background function that is calling this function when an overlay moves on the screen:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay

MKAnnotions 我觉得它好一点,但我不能使用 MKPolyline MKPolygon 等等,整个信息减少到一个点)

(with MKAnnotions its a little better i think, but i cant use MKPolyline, MKPolygon, etc. and the whole information is reduced to a single point)

推荐答案

MKOverlayView 具有以下方法,迫使MapKit重新渲染给定的mapRect :

MKOverlayView has the following methods which force MapKit to re-render the given mapRect:

- (void)setNeedsDisplayInMapRect:(MKMapRect)mapRect

- (void)setNeedsDisplayInMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale

如果你'使用计时器(或定期HTTP请求或某种其他方法用于检测告知你的叠加层应该更新),在overlayView上调用上述方法之一会导致它在地图上重新渲染那个点(即将再次调用 -canDrawMapRect:zoomScale:,然后将调用 -drawMapRect:zoomScale:inContext:前者返回YES)。

If you’re using a timer (or periodical HTTP request or some sort of other method for determining that your overlay should be updated), calling one of the above methods on the overlayView will cause it to re-render that spot on the map (i.e. -canDrawMapRect:zoomScale: will be called again, and then -drawMapRect:zoomScale:inContext: will be called if the former returns YES).

更新:

如果你'我不确定你需要重新渲染的mapRect,可能能够使用 MKMapRectWorld 常量作为mapRect - 我认为导致整个地图上的叠加层重新加载(一旦可见)。

If you’re not sure what mapRect you need to re-render, you might be able to use the MKMapRectWorld constant as the mapRect — which I believe would cause the overlay across the entire map to reload (once visible).

这篇关于在MKMapView上移动/更新MKOverlay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆