我正在调用Web服务并在MapView上绘制一些对象.
我无法理解的是我应该使用MKAnnotationPoint还是MkAnnotationView?我不确定.当我使用MKAnnotation时,引脚会显示在地图上,如果我点击它们,它们会显示标题和副标题.
如果我使用MKAnnotationView,引脚会显示,但是当我点击它们时,没有任何反应.
我也试图添加右按钮标注/雪佛龙看按钮,但也无法弄清楚.
这是我的代码示例.
MKPointAnnotation mk = new MKPointAnnotation();
MKAnnotationView mkView = new MKAnnotationView();
mk.Coordinate = coord;
mk.Title = tl.Name;
mk.Subtitle = DateTime.Now.ToShortDateString();
mkView.Annotation = mk;
mapView.AddAnnotationObject(mkView);
Run Code Online (Sandbox Code Playgroud)
因此,如果我执行上述操作 - 引脚显示,但我无法点击它们中的任何一个.
如果我只是使用:
mapView.AddAnotationObject(mk); //not using the MkAnnotationView
Run Code Online (Sandbox Code Playgroud)
然后它们都显示出来并且是可点击的.我不知道如何向他们添加rightcalloutbutton.所以这是问题的第二部分.
谢谢.
我的理解是移动到iOS 6地图没有问题.但由于某种原因,详细信息披露按钮现在在我的地图App中丢失.有没有办法让这个回来.哇,完全出乎意料.这已经工作多年了,所以所有代表都很好.
#pragma mark MKMapViewDelegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKPinAnnotationView *pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"REUSEME"] autorelease];
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
if ([annotation isKindOfClass:[MKUserLocation class]]) {
pin.animatesDrop = YES;
return nil;
} else {
[pin setPinColor:MKPinAnnotationColorGreen];
}
pin.rightCalloutAccessoryView = button;
pin.animatesDrop = YES;
pin.canShowCallout = YES;
return pin;
}
Run Code Online (Sandbox Code Playgroud) 我是一位经验丰富的iOS开发人员,但这确实让我感到难过。我正在同时向苹果提交问题报告。
我正在向MKMapKit地图(Xcode 4.6)添加注释。每个注释都是MyAnnotation类;MyAnnotation定义了一个属性location_id,我用它来跟踪该注释。
问题很简单:我希望location_id为-1的MyAnnotation出现在其他所有内容的前面。
为此,我在我的MKMapViewDelegate中覆盖了mapView:didAddAnnotationViews ::
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
// Loop through any newly added views, arranging them (z-index)
for (MKAnnotationView* view in views) {
// Check the location ID
if([view.annotation isKindOfClass:[MyAnnotation class]] && [((MyAnnotation*)(view.annotation)).location_id intValue]==-1 ) {
// -1: Bring to front
[[view superview] bringSubviewToFront:view];
NSLog(@"to FRONT: %@",((MyAnnotation*)view.annotation).location_id);
} else {
// Something else: send to back
[[view superview] sendSubviewToBack:view];
NSLog(@"to BACK: %@",((MyAnnotation*)view.annotation).location_id);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这很好。我有一个“添加”按钮,可将注释添加到地图中心附近的随机位置。每次我按“添加”按钮,都会出现一个新注释。但没有任何东西会隐藏location_id为-1的注释。
**直到**我滚动!
一旦开始滚动,便会重新排列所有注释(z顺序),不再适用我的仔细堆叠。
真正令人困惑的是,我之前毫无问题地完成了图标顺序堆叠。我已经创建了一个全新的单视图应用程序来测试该问题。向后或向前发送MKAnnotationView项目仅在滚动之前有效。除了上面描述的代码外,此骨架应用程序中没有其他内容。我想知道最新的MapKit框架中是否存在某种错误。
最初的问题是在用户滚动时尝试添加新的注释(mapView:regionDidChangeAnimated :)。注释添加;mapView:didAddAnnotationViews:代码触发;然后顺序在框架中被看不见的手打乱(大概是在滚动完成时)。
如果您有兴趣,这是我的viewForAnnotation:
-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { …Run Code Online (Sandbox Code Playgroud) 我有一个叠加的路线放在地图上.我必须调整它的旋转,使其与底层地图视图完全重叠.我怎样才能做到这一点?我找到了旋转的角度.如何旋转叠加视图?到目前为止,我已经添加了叠加层,但无法使用变换进行旋转.我注意到的是,当我改变角度时,图像不会旋转,而是沿x轴(侧面)滑动.
这是我试过的代码
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"routeImage" ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];
MKMapRect theMapRect = self.overlay.boundingMapRect;
CGRect theRect = [self rectForMapRect:theMapRect];
CGAffineTransform transform = CGAffineTransformMakeRotation((-35.88) / 180.0 * M_PI);
[self setTransform:transform];
CGContextSaveGState(context);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0.0, -theRect.size.height);
CGContextDrawImage(context, theRect,image.CGImage);
CGContextRestoreGState(context);
}
Run Code Online (Sandbox Code Playgroud)
这就是我得到的

我有一个解决方法,我使用GIMP手动旋转图像并放置它.但我需要它来定制.
这是使用GIMP转换的图像,当作为叠加层放置在地图上时
这是我使用变换旋转上下文时[注意:旋转上下文时图像旋转但不在确切的位置见图像.此外,图像在缩放时中断]
这就是我做的
//Hayl-Road-Final.png is the actual image without transformation using GIMP
UIImage *image = [[UIImage imageNamed:@"Hayl-Road-Final.png"] retain];
CGImageRef imageReference = image.CGImage;
MKMapRect theMapRect …Run Code Online (Sandbox Code Playgroud) Swift中是否有可能在MapKit中聚类标记?我知道在Google Maps SDK中可以使用,但我在MapKit中找不到相同的功能.我找到了一些Obj-C的库,但没有为Swift找到
我找到的一些库:
我正在开发一个应用程序,它在很大程度上依赖于监视可能在多个地区/区域中的用户访问.我目前正在尝试区域监控工作得很好,但是,位置回调并不像我想要的那样准确.我见过CLVisit,但那里的文档并没有很好地解释它,特别是它的使用.
我认为标题是非常自我解释的.目前,当我为当前位置添加默认注释时:
let currentAnnot = MKPointAnnotation()
currentAnnot.coordinate = loc.coordinate
mainMap.addAnnotation(currentAnnot)
Run Code Online (Sandbox Code Playgroud)
它给了我一个红色别针.我想要与Apple iPhone地图应用程序默认使用的浅蓝色字段相同的蓝点.是否有特殊名称,如何添加?
我需要绘制一个以坐标列表(P1,P2,... Pn)开头的路径.对于我的列表中的每个下一对Pi,Pj,我调用calculateDirectionsWithCompletionHandler类的方法MKDirections直到Pn-1元素.我第一次称之为一切看起来都很完美.但是,如果我第二次或更远的时间,我会收到此错误:
Error Domain=MKErrorDomain Code=3 "Directions Not Available" UserInfo={NSLocalizedFailureReason=Route information is not available at this moment., MKErrorGEOError=-4, MKDirectionsErrorCode=2, NSLocalizedDescription=Directions Not Available}
Run Code Online (Sandbox Code Playgroud)
并且没有任何作品了.
我认为这是因为我在很短的时间内调用了API太多次了.我在网上发现我应该使用该属性direction.calculating并检查请求是否已在进行中.我无法理解如何使用它.有人可以帮帮我吗?谢谢.
MKMapView提供了几种方法,可以让您设置可见地图rect(或区域,坐标范围等).这些方法具有动画参数,当设置为true时,使用大约0.3秒的线性动画来为变化设置动画.
虽然这很好,但我想复制Apple 在点击地图时在他的" 查找我的朋友"和" 查找我的iPhone"应用程序中使用的动画.如果你自己尝试一下,你会发现一个非线性曲线的动画要快得多(大约0.15秒).现在,我们称之为"反弹 - 缩放"过渡.
我想要复制非线性动画曲线和自定义动画持续时间.在UIView的animateWithSpring ...方法中包装地图更新似乎不起作用(我当然可能做错了).非常清楚Apple可能有能力做MKMapView API中没有公开的东西,但Apple的App Store分布式应用程序通常似乎坚持他们关于公共API的指导方针.
这可能吗?如果是这样 - 怎么样?仅仅改变动画持续时间并不是我追求的.我也想控制动画曲线.
在这里看到一个试图做上述操场的游乐场.请注意,MKMapView似乎考虑了动画持续时间,但不考虑弹性,例如Find my iPhone/Find my Friends.
我正在尝试向地图添加注释。我内部有坐标的点数组。我正在尝试从这些坐标添加注释。
我有这个定义:
var points: [CLLocationCoordinate2D] = [CLLocationCoordinate2D]()
let annotation = MKPointAnnotation()
Run Code Online (Sandbox Code Playgroud)
点内部具有坐标。我检查了。我这样做:
for index in 0...points.count-1 {
annotation.coordinate = points[index]
annotation.title = "Point \(index+1)"
map.addAnnotation(annotation)
}
Run Code Online (Sandbox Code Playgroud)
它一直仅添加最后一个注释...而不是全部添加。为什么是这样?顺便说一句,有没有办法删除指定的注释,例如按标题?
mapkit ×10
ios ×4
swift ×4
iphone ×2
xcode ×2
annotations ×1
c# ×1
directions ×1
ios6 ×1
ios6-maps ×1
mkmapview ×1
mkoverlay ×1
swift3 ×1
xamarin.ios ×1