关于地图问题的注释 [英] Annotation on the map problem

查看:384
本文介绍了关于地图问题的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a map app where the user can tag a map with a photo, comment or video, but I am having a problem putting an annotation on the map.

我的情况是这样的:

在第一页上,用户可以看到三个带有地图的按钮(1.photo,2.comment和3.video).当他想通过单击照片按钮标记地图时.我使用cammerView类,它提供了另外三个按钮(1.拍照,2.选择照片和3.use照片);拍照后,他可以选择是否使用照片.如果他想使用这张照片,则屏幕必须移至地图页面,并且注释必须删除.

On the 1st page, the user can see three button with the map (1.photo, 2.comment and 3.video). When he wants to tag the map by clicking on the photo button. I use cammerView class, which gives three more buttons (1.take photo, 2.choose photo and 3.use photo); after taking a photo he has a choice of using photo or not. If he wants use this photo the screen must move to the map page, and the annotation must drop.

我遇到问题了.我无法弄清楚如何在当前位置的用户地图上放置注释.单击照片类上的使用"按钮后,必须删除此注释.

I am getting problem. I cannot figure out how to drop the annotation on user's map at the current location. This annotation must drop after the clicking the use button which on the photo class.

我还尝试了

I also tried this sample application, but in my case I need to have the annotation drop on the map from a button that is on the same page. How can I make this work?

推荐答案

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

Code from Class1.m (Where Your button is touched):

- (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];
}

#Class2.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;
}

这里是最后一个支持类:

And here last Supportive Class:

#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

这篇关于关于地图问题的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆