地图问题注释



我正在尝试创建一个地图应用程序,用户可以在其中用照片、评论或视频标记地图,但我在地图上添加注释时遇到了问题。

我的场景是这样的:

在第一个页面上,用户可以看到带有地图的三个按钮(1.照片、2.评论和3.视频)。当他想通过点击照片按钮来标记地图时。我使用cammerView类,它又提供了三个按钮(1.拍照,2.选择照片和3.使用照片);拍完照片后,他可以选择是否使用照片。如果他想使用这张照片,屏幕必须移动到地图页面,并且必须删除注释。

我遇到问题了。我不知道如何将注释放在用户地图上的当前位置。此注释必须在单击照片类上的使用按钮后删除。

我也尝试过这个示例应用程序,但在我的情况下,我需要从同一页面上的按钮将注释放到地图上。我怎样才能做到这一点?

Class1.m中的代码(触摸按钮的位置):

#Class1.m

- (void) trackImageOnMapButtonTouched
{
    MapView *tempView =[[MapView alloc] initWithNibName:@"MapView" bundle:[NSBundle mainBundle]];
    self.moveToMapView=tempView;
    [tempView release];
    int iId=[mainSlideShowImageView tag];
    self.moveToMapView.fromFlag_imageId=[NSString stringWithFormat:@"%d",iId];
    self.moveToMapView.slideShowView_imageOnSlide=[NSString stringWithFormat:@"%d",[mainSlideShowImageView tag]];
    NSLog(@"self.moveToMapView.slideShowView_imageOnSlide=%@",self.moveToMapView.slideShowView_imageOnSlide);
    [self.view addSubview:moveToMapView.view];
}

#等级2.m

- (void) viewDidLoad
{
    self.lattitudeArray=[[NSMutableArray alloc] init];
    self.longitudeArray=[[NSMutableArray alloc] init];
    MKCoordinateRegion region;
    MKCoordinateSpan span;
    CLLocationCoordinate2D location;
    span.latitudeDelta=2.0;
    span.longitudeDelta=2.0;
    location.latitude=43.25f;
    location.longitude=11.00f;
    region.span=span;
    region.center=location;

    addAnnotation = [[MapViewAnnotation alloc] initWithLocation:location withTitle:[NSString stringWithFormat:@"Tuscany"] withSubTitle:[NSString stringWithFormat:@"Italy"] withImage:[UIImage imageNamed:@"1.jpg"]];
    addAnnotation.mTitle=[NSString stringWithFormat:@"Tuscany"];
    addAnnotation.mSubTitle=[NSString stringWithFormat:@"Italy"];
    [mapView addAnnotation:addAnnotation];
    [mapView setRegion:region animated:TRUE];
    [mapView regionThatFits:region];
    mapView.mapType = MKMapTypeHybrid;   // also MKMapTypeSatellite or MKMapTypeHybrid
}

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
    annView.pinColor = MKPinAnnotationColorPurple;
    annView.animatesDrop=TRUE;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);

    NSString *imageName=[NSString stringWithFormat:@"%@.jpg",self.fromFlag_imageId];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullImgNm=[documentsDirectory stringByAppendingPathComponent:[NSString stringWithString:imageName]];
    UIImage *actualImage=[UIImage imageWithContentsOfFile:fullImgNm];
    CGSize annImgSize;
    annImgSize.width=60;
    annImgSize.height=30;
    UIImage *locationImage=[self resizeImage:actualImage withSize:annImgSize];
    [rightButton setImage:locationImage forState:UIControlStateNormal];
    [rightButton addTarget:self
                    action:@selector(annotationPinClicked:)
          forControlEvents:UIControlEventTouchUpInside];
    annView.leftCalloutAccessoryView=rightButton;
    return annView;
}

最后一个支持类:

.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MapViewAnnotation : NSObject <MKAnnotation>
{
    CLLocationCoordinate2D coordinate;
    NSString *mTitle;
    NSString *mSubTitle;
}
@property (nonatomic, retain) NSString *mTitle;
@property (nonatomic, retain) NSString *mSubTitle;
-(id)initWithLocation:(CLLocationCoordinate2D)location withTitle:(NSString *)title withSubTitle:(NSString *)subTitle withImage:(UIImage *)locationImage;
//- (CLLocationCoordinate2D)initWithLocation:(CLLocationCoordinate2D) location;

@end

.m:

#import "MapViewAnnotation.h"
@implementation MapViewAnnotation
@synthesize coordinate;
@synthesize mTitle,mSubTitle;
-(id)initWithLocation:(CLLocationCoordinate2D)location withTitle:(NSString *)title withSubTitle:(NSString *)subTitle withImage:(UIImage *)locationImage
{
    coordinate.latitude = location.latitude;
    coordinate.longitude = location.longitude;
    return self;
}
-(NSString *)title
{
    return mTitle;
}
-(NSString *)subtitle
{
    return mSubTitle;
}
- (void) dealloc{
    [mTitle release];
    [mSubTitle release];
    [super dealloc];
}
@end

最新更新