我编写了简单的mapView应用程序。它显示了两种问题。
1-执行在线程1停止:信号SIGABRT错误。
2-此函数显示编译时错误。
- (IBAction)findMe:(id)sender {
If( [[toggleButton titleForState:UIControlStateNormal] isEqualToString:@"Find Me"] )
{
[toggleButton setTitle:@"Hide Me" forState:UIControlStateNormal];
mapView.showsUserLocation=YES;
}
else
{
[toggleButton setTitle:@"Find Me" forState:UIControlStateNormal];
mapView.showsUserLocation=NO;
}
}
如何删除这些错误?
我想在我的代码中放置多个位置的坐标我希望在地图上显示loc.png图标,对应于那些坐标我将如何完成此任务?
您可以通过以下链接查看示例项目:https://drive.google.com/open?id=0B5pNDpbvZ8SnRmNFS0pjVnJFWHc
答案 0 :(得分:0)
由于以下三个原因,您收到编译时错误:
1)你在if-else条件下使用的“If”应该是“if”,即小写。
2)。您有一个IBOutlet连接到storyboard中的findMe按钮,在视图控制器中不存在。所以要么删除它,要么添加它。
3)您正在使用MKMapView,但您没有在项目的构建阶段选项的“链接二进制文件”中添加MapKit框架。
请执行所有这些步骤以编译代码并进行编译。执行错误。
答案 1 :(得分:0)
回答您的问题:
我想在我的代码中放置多个位置的坐标我希望在地图上显示loc.png图标,这些坐标对应于我如何完成此任务?
以下是ViewController.h的代码
onActivate

以下是ViewController.m的代码
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate>
@end
&#13;
添加新文件MyAnnotation.h / MyAnnotation.m
以下是MyAnnotation.h的代码
#import "ViewController.h"
#import "MyAnnotation.h"
#import <MapKit/MapKit.h>
@interface ViewController ()
@property (strong, nonatomic) IBOutlet MKMapView *myMapView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// setup the map view, delegate and current location
[self.myMapView setDelegate:self];
self.myMapView.mapType = MKMapTypeStandard;
CLLocationCoordinate2D myLocation = CLLocationCoordinate2DMake(25.085130,-77.331428);
[self.myMapView setCenterCoordinate:myLocation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(myLocation, 2000, 2000);
region.center = self.myMapView.centerCoordinate;
self.myMapView.showsUserLocation = YES;
[self.myMapView setRegion:region animated:YES];
[self dropPins];
}
-(void)dropPins {
NSMutableArray *annotationArray = [[NSMutableArray alloc] init];
CLLocationCoordinate2D location1 = CLLocationCoordinate2DMake(25.085130, -77.331428);
MyAnnotation *annotation1 = [[MyAnnotation alloc] initWithCoordinates:location1 image:@"loc.png"];
[annotationArray addObject:annotation1];
[self.myMapView addAnnotations:annotationArray];
[annotationArray removeAllObjects];
CLLocationCoordinate2D location2 = CLLocationCoordinate2DMake(25.085130, -77.336428);
MyAnnotation *annotation2 = [[MyAnnotation alloc] initWithCoordinates:location2 image:@"loc.png"];
[annotationArray addObject:annotation2];
[self.myMapView addAnnotations:annotationArray];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[MyAnnotation class]])
{
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.myMapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil)
{
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else
{
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = NO;
if([[(MyAnnotation *)annotationView.annotation image] isEqualToString:@"pin1.png"])
annotationView.image = [UIImage imageNamed:@"loc.png"];
if([[(MyAnnotation *)annotationView.annotation image] isEqualToString:@"pin2.png"])
annotationView.image = [UIImage imageNamed:@"loc.png"];
return annotationView;
}
return nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
&#13;
以下是MyAnnotation.m的代码
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MyAnnotation : NSObject <MKAnnotation>
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy, readonly) NSString *image;
-(id)initWithCoordinates:(CLLocationCoordinate2D) paramCoordinates
image:(NSString *) paramImage;
@end
&#13;