我做了一个演示项目(来自github上的Moving-MKAnnotationView演示),用于在地图上移动汽车以下是它的链接
https://github.com/pratikbhiyani/Moving-MKAnnotationView
我在vinaut的给定答案的基础上编辑我的代码,但问题是,当我们缩放或滚动地图动画时,在我们缩放或滚动地图注释设置为其原始角度一段时间时,在ios 7和ios 6中分散注意力.
下面是我的演示项目的屏幕截图

这是我改变的一些代码
- (void) setPosition : (id) posValue;
{
NSLog(@"set position");
//extract the mapPoint from this dummy (wrapper) CGPoint struct
MKMapPoint mapPoint = *(MKMapPoint*)[(NSValue*)posValue pointerValue];
CLLocationCoordinate2D coord = MKCoordinateForMapPoint(mapPoint);
CGPoint toPos;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
toPos = [self.mapView convertCoordinate:coord toPointToView:self.mapView];
}
else
{
CGFloat zoomFactor = self.mapView.visibleMapRect.size.width / self.mapView.bounds.size.width;
toPos.x = mapPoint.x/zoomFactor;
toPos.y = mapPoint.y/zoomFactor;
}
[self setTransform:CGAffineTransformMakeRotation([self getHeadingForDirectionFromCoordinate:MKCoordinateForMapPoint(previousPoint) toCoordinate: MKCoordinateForMapPoint(mapPoint)])];
if (MKMapRectContainsPoint(self.mapView.visibleMapRect, mapPoint)) {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; …Run Code Online (Sandbox Code Playgroud) 我有一个可以快速更新的注释数据集.目前我删除所有注释,然后将它们重新绘制回地图上.
NSArray *existingpoints = [mapView.annotations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"!(self isKindOfClass: %@)", [MKUserLocation class]]];
[mapView removeAnnotations:existingpoints];
Run Code Online (Sandbox Code Playgroud)
我在自定义对象中计算它们的位置,因此希望能够调用它并"移动"注释而不删除并将其重新添加回地图.我制作的示例调用工作,我想几乎"民意调查"在下面.
- (CLLocationCoordinate2D) coordinate
{
CLLocationCoordinate2D coord;
coord.latitude = [lat doubleValue];
coord.longitude = [lon doubleValue];
double differencetime = exampleTime;
double speedmoving;
double distanceTravelled = speedmoving * differencetime;
CLLocationDistance movedDistance = distanceTravelled;
double radiansHeaded = DEG2RAD([self.heading doubleValue]);
CLLocation *newLocation = [passedLocation newLoc:movedDistance along:radiansHeaded];
coord = newLocation.coordinate;
return coord;
}
Run Code Online (Sandbox Code Playgroud)
根据要求,Object的.h文件,我没有SetCoordinate方法..
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface TestObject : NSObject <MKAnnotation>{
NSString *adshex;
NSString *lat;
NSString *lon;
NSString …Run Code Online (Sandbox Code Playgroud) 我有一个从MKOverlayPathView继承的地图自定义视图.我需要这个自定义视图来显示圆,线和文本.
我已经设法使用路径绘制CGPathAddArc和CGPathAddLineToPoint函数绘制圆和线.
但是,我仍然需要添加文字.
我尝试使用添加文本
[text drawAtPoint:centerPoint withFont:font];
Run Code Online (Sandbox Code Playgroud)
但我得到了无效的上下文错误.
任何的想法?