NSInvalidUnarchiveOperationException',原因:'*** - [NSKeyedUnarchiver decodeObjectForKey:]:无法解码类的对象(MKMapView)
我收到了这个错误.我错过了什么?
我不知道从哪里添加Mapkit框架.首先我尝试了target->getInfo,然后从底部+标志添加框架,但这不起作用.然后我在聚光灯下搜索并添加了另一个框架.通过添加它,它删除了以前的错误,但给出了上面的错误.
Mapkit框架的确切位置是什么?我想在模拟器中测试它.
在我的iphone应用程序中,我使用MapKit和MKMapView以及自定义MKAnnotationView.
问题是当注释在地图上重叠时(在我的应用中,注释是照片而这些照片可能重叠),当你点击前面出现的注释时,它是另一个注释(在背面)接收事件(似乎是随机的) ).
我没有找到任何方法将事件发送到前端注释.我不敢相信这个bug /问题没有任何解决方案!
stackoverflow上的Z排序和重叠注释问题的顺序对我没有多大帮助.
欢迎任何想法(即使是肮脏的解决方案)!
这是我的一些代码(没什么特别的,很常见):
CustomAnnotation.h
@interface CustomAnnotation : NSObject <MKAnnotation> {
@private
CustomAnnotationView* view;
}
@property (nonatomic, retain) CustomAnnotationView* view;
@end
Run Code Online (Sandbox Code Playgroud)
CustomAnnotation.m
@implementation CustomAnnotation
@synthetize view;
Run Code Online (Sandbox Code Playgroud)
CustomAnnotationView.h
@interface CustomAnnotationView : MKAnnotationView {
}
@end
Run Code Online (Sandbox Code Playgroud)
CustomAnnotationView.m
@implementation CustomAnnotationView
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
// Do something related to the annotation tapped
}
@end
Run Code Online (Sandbox Code Playgroud)
主类... //添加了注释,其中一些与其他注释重叠.
- (void)addAnnotation:(CustomAnnotation*)annotation {
[map addAnnotation:annotation];
}
...
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
NSString* identifier …Run Code Online (Sandbox Code Playgroud) 这是关于使用MKMapKit的iPhone App:
我为可拖动的注释创建了一个自定义MKAnnotationView.我想创建一个自定义动画.我设置了一个自定义图钉图像,注释是可拖动的(这里没有显示,它发生在mapview中),代码如下:
- (void) movePinUpFinished {
[super setDragState:MKAnnotationViewDragStateDragging];
[self setDragState:MKAnnotationViewDragStateDragging];
}
- (void) setDragState:(MKAnnotationViewDragState) myState {
if (myState == MKAnnotationViewDragStateStarting) {
NSLog(@"starting");
CGPoint endPoint = CGPointMake(self.center.x,self.center.y-20);
self.center = endPoint;
[self movePinUpFinished];
}
if (myState == MKAnnotationViewDragStateEnding) {
NSLog(@"ending");
[super setDragState:MKAnnotationViewDragStateEnding];
[self setDragState:MKAnnotationViewDragStateNone];
[super setDragState:MKAnnotationViewDragStateNone];
}
if (myState == MKAnnotationViewDragStateDragging) {
NSLog(@"dragging");
}
if (myState == MKAnnotationViewDragStateCanceling) {
NSLog(@"cancel");
}
if (myState == MKAnnotationViewDragStateNone) {
NSLog(@"none");
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,注释向上移动一点,可拖动,当我发布注释时,mapview会收到"dragstateending".
但现在我希望动画在一段时间内运行并将dragStateStarting更改为以下内容:
if (myState == MKAnnotationViewDragStateStarting) {
NSLog(@"starting");
CGPoint endPoint = CGPointMake(self.center.x,self.center.y-20); …Run Code Online (Sandbox Code Playgroud) 我有一个MKOverlayView,它将动画雷达数据显示为一系列图像.我的问题是MapKit将雷达图像切割成瓷砖.为了交换图像,我有一个调用更新功能的计时器,它在我的叠加层中设置当前图像,然后调用以下内容
[myRadarOverlayView setNeedsDisplayInMapRect:self.mapView.visibleMapRect];
Run Code Online (Sandbox Code Playgroud)
叠加层更新,但一次只有一个瓦片,所以我得到了一个不稳定的动画.关于如何在同一时间使所有瓷砖动画(即交换图像)的任何想法?
我已经构建了一个应用程序,旨在显示一些叠加层.覆盖层采用多边形的形式,外圈最多10000个点.但是大量的观点似乎不是问题所在.在过去的几天里,我一直在简化我的应用,只是为了找到一个包含MapView的简单视图.视图从xib加载(连接了出口和委托).叠加是在方法中创建的 - (void)mapView:(MKMapView*)mapView regionDidChangeAnimated:(BOOL)动画并添加到mapView.
演示(可在此处https://github.com/nebucaz/mapkit)显示MapView,并在地图放大/缩小或平移时添加红色三角形.在玩MapView的缩放和平移(密集和快速)时,应用程序崩溃了.很容易为模拟器而烦恼,即使有可能(我可以提供崩溃日志),它在设备上也要难得多.
有两个演示:MapCrash和MapCrashStatic.第一个在地图周围创建多个多边形,具体取决于平移/缩放的位置.第二个只有一个静态多边形,它在 - (void)viewDidLoad中创建,然后在每次调用mapView时添加了regionDidChangeAnimated
应用程序总是崩溃与以下回溯:
Attaching to process 8745.
MapCrash(8745) malloc: protecting edges
[Switching to process 8745 thread 0x1820b]
[Switching to process 8745 thread 0x1820b]
(gdb) backtrace
#0 0x00000000 in ?? ()
#1 0x00e81a60 in CG::Path::apply_transform ()
#2 0x00ed741c in CGPathCreateMutableCopyByTransformingPath ()
#3 0x00f50d23 in CGContextAddPath ()
#4 0x000f11dc in MKRoadWidthAtZoomScale ()
#5 0x000ee498 in MKMapRectRemainder ()
#6 0x000fab01 in MKTilesRequireGoogleLegalNotices ()
#7 0x02723c17 in -[CALayer drawInContext:] ()
#8 0x027407e3 in tiled_layer_render ()
#9 …Run Code Online (Sandbox Code Playgroud) 我在Path风格的视差表视图标题中显示MKMapView.要创建效果,mapView边界大于用户可见的区域.我需要设置地图视图区域,以便所有地图的注释都包含在MKMapView的可见矩形中.最好的方法是什么?

为清晰起见编辑:这是一个用例.mapView大小为320 x 380.但是,可见区域由rect(0.0,20.0,320.0,100.0)定义.我需要设置区域,以便所有注释都出现在mapView中的此rect中.
我使用此代码打开地图应用程序
NSString* versionNum = [[UIDevice currentDevice] systemVersion];
NSString *nativeMapScheme = @"maps.apple.com";
if ([versionNum compare:@"6.0" options:NSNumericSearch] == NSOrderedAscending){
nativeMapScheme = @"maps.google.com";
}
NSString* url = [NSString stringWithFormat:@"http://%@/maps?ll=%f,%f", nativeMapScheme, 40.739490, -73.991154];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Run Code Online (Sandbox Code Playgroud)
似乎它运作良好,但我使用的这个位置没有引脚.如何添加引脚,我想在请求中还有其他参数?
我试图了解如何使用Swift绘制折线.我查看了文档,引用了一些教程,并查看了其他一些SO帖子,但我仍然无法在地图上画一条线.这是我的代码.有谁告诉我这里我做错了什么?
import UIKit
import MapKit
class FirstViewController: UIViewController {
@IBOutlet weak var map: MKMapView!
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let location = CLLocationCoordinate2D(
latitude: -73.761105,
longitude: 41.017791
)
let span = MKCoordinateSpanMake(0.07, 0.07)
let region = MKCoordinateRegion(center: location, span: span)
map.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.setCoordinate(location)
annotation.title = "White Plains"
annotation.subtitle = "Westchester County"
map.addAnnotation(annotation)
var locations = [CLLocation(latitude: -73.761105, longitude: 41.017791), CLLocation(latitude: -73.760701,longitude: 41.019348), CLLocation(latitude: -73.757201, longitude: 41.019267), CLLocation(latitude: -73.757482, longitude: 41.016375), CLLocation(latitude: -73.761105, longitude: 41.017791)] …Run Code Online (Sandbox Code Playgroud) 我正在传递地图的选项,但这似乎与缩放级别没有任何关系?它保持相同的低缩放级别.我错过了什么?
func openMapForPlace() {
let regionDistance:CLLocationDistance = 10000
var coordinates = CLLocationCoordinate2DMake(detailItem!.geoLatitude, detailItem!.geoLongitude)
let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance)
var options = [
MKLaunchOptionsMapCenterKey: NSValue(MKCoordinate: regionSpan.center),
MKLaunchOptionsMapSpanKey: NSValue(MKCoordinateSpan: regionSpan.span)
]
var placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
var mapItem = MKMapItem(placemark: placemark)
mapItem.name = detailItem!.cityName
mapItem.openInMapsWithLaunchOptions(options)
}
Run Code Online (Sandbox Code Playgroud) 此时,我正在试图弄清楚MKMapView上的坐标是否在提前绘制出的纬度/经度的MKPolygon内.
我正在使用CGPathContainsPoint来确定坐标是否在地图上的多边形内,但无论我选择哪个坐标,它总是返回false.
任何人都可以解释究竟出了什么问题?下面是我在Swift中的代码.
class ViewController: UIViewController, MKMapViewDelegate
@IBOutlet weak var mapView: MKMapView!
let initialLocation = CLLocation(latitude: 43.656734, longitude: -79.381576)
let point = CGPointMake(43.656734, -79.381576)
let regionRadius: CLLocationDistance = 500
let point1 = CLLocationCoordinate2D(latitude: 43.656734, longitude: -79.381576)
var points = [CLLocationCoordinate2DMake(43.655782, -79.382094),
CLLocationCoordinate2DMake(43.657499, -79.382310),
CLLocationCoordinate2DMake(43.656656, -79.380497),
CLLocationCoordinate2DMake(43.655782, -79.382094)]
override func viewDidLoad() {
super.viewDidLoad()
centerMapOnLocation(initialLocation)
let polygon = MKPolygon(coordinates: &points, count: points.count)
mapView.addOverlay(polygon)
var annotation = MKPointAnnotation()
annotation.coordinate = point1
annotation.title = "Test"
annotation.subtitle = "Test"
mapView.addAnnotation(annotation)
self.mapView.delegate = self
}
func …Run Code Online (Sandbox Code Playgroud) mapkit ×10
ios ×6
objective-c ×3
swift ×3
iphone ×2
mkannotation ×2
mkmapview ×2
mkpolyline ×2
animation ×1
cocoa-touch ×1
crash ×1
ios4 ×1
ios8 ×1
map ×1
mkoverlay ×1
mkpolygon ×1
overlay ×1
polyline ×1
xcode ×1