简体   繁体   中英

ios MapKit, following a path

I have a path rendering on my map. I have a series of waypoints and I'm simulating movement through them.

When changing the display region it appears that my coordinate when converted to a CGPoint is floorf by Apple's implementation. This causes a very jittery appearance instead of a smooth one.

Is there anyway to get around this?

[m_mapView setRegion: MKCoordinateRegionMake(coord, MKCoordinateSpanMake(0, 0))];

The map then tries to center on this given point. However the point may not be pixel aligned as can be view by the following function.

CGPoint point = [m_mapView convertCoordinate:coord toPointToView:m_mapView];

Thus the mapview floors the centerpoint's result to align all pixels for the underlying map.

I make the view larger than the screen to account for the offset and to avoid clipping.

I simulate a point moving along the route and place it using an annotation and then center on that point at 30 frames per second.

Assume coord is the position of the moving point.

[m_mapView setCenterCoordinate: coord];

CGPoint p = [m_mapView convertCoordinate:m_mapView.centerCoordinate toPointToView:m_mapView];
CGPoint p1 = [m_mapView convertCoordinate:coord toPointToView:m_mapView];

CGPoint offset = CGPointMake(p.x - p1.x, p.y - p1.y);
CGRect frame = CGRectInset(CGRectMake(0.0f, 0.0f, 1024.0f, 1024.0f), -50.0f, -50.0f);
frame.origin.x+= offset.x;
frame.origin.y+= offset.y;
[m_mapView setFrame: frame];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM