2014-05-03 1 views
1

Я пытаюсь создать карту с такими фотографиями, как Instagrams Photo Map.карта с фотографиями, такими как Instagram Photo Map

Фото Карта: http://i.stack.imgur.com/B0wDa.jpg

Как я могу получить изображение (загруженное из Parse), в аннотации, как в приведенном выше скриншоте?

И это то, что я до сих пор: MapViewController.m

[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) { 
     PFQuery *query = [PFQuery queryWithClassName: @"HomePopulation"]; 
     [query whereKey:@"geopoint" nearGeoPoint:geoPoint withinKilometers:3000]; 
     [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
      if (!error) { 
       for (PFObject *object in objects) { 
        PFGeoPoint *thePoint = [object objectForKey:@"geopoint"]; 
        latitude = thePoint.latitude; 
        longitude = thePoint.longitude; 

        NSLog(@" Hej %f, %f", latitude, longitude); 
        CLLocationCoordinate2D annotationCoordinate = CLLocationCoordinate2DMake(latitude, longitude); 

        Annotation *annotation = [[Annotation alloc] init]; 
        annotation.coordinate = annotationCoordinate; 
        annotation.title = [object objectForKey:@"discovery"]; 
        annotation.subtitle = [object objectForKey:@"location"]; 

        PFFile *image = [object objectForKey:@"imageFile"]; 
        annotation.imageView.file = image; 
        [annotation.imageView loadInBackground]; 

        [self.theMap addAnnotation:annotation]; 

        [self.theMap setCenterCoordinate:annotation.coordinate animated:YES]; 

        [self setNeedsStatusBarAppearanceUpdate]; 
       } 
      } 
     }]; 
    }]; 

Любая помощь приветствуется. Марко

+0

Что точная проблема или вопрос? – Anna

+0

Как я могу получить изображение (загруженное из Parse), в аннотацию, как на скриншоте выше? – zzzel

ответ

1

С помощью этого обсуждения: Custom annotations with same image

Я вышел с этим: My Photo Map

Вот код:

MapViewController.h 
#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 
#import <Parse/Parse.h> 


@interface MapViewController : UIViewController <MKMapViewDelegate> 

@property double latitude; 
@property double longitude; 


@end 

MapViewController.m 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [self.navigationController setNavigationBarHidden:YES animated:YES]; 
    self.theMap.delegate = self; 
    self.theMap.showsUserLocation = YES; 

    [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) { 
     PFQuery *query = [PFQuery queryWithClassName: @"HomePopulation"]; 
     [query whereKey:@"geopoint" nearGeoPoint:geoPoint withinKilometers:1000]; 
     [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
      if (!error) { 
       for (PFObject *object in objects) { 
        PFGeoPoint *thePoint = [object objectForKey:@"geopoint"]; 
        latitude = thePoint.latitude; 
        longitude = thePoint.longitude; 

        NSLog(@" Hej %f, %f", latitude, longitude); 
        CLLocationCoordinate2D annotationCoordinate = CLLocationCoordinate2DMake(latitude, longitude); 

        Annotation *annotation = [[Annotation alloc] init]; 
        annotation.coordinate = annotationCoordinate; 
        annotation.title = [object objectForKey:@"discovery"]; 
        annotation.subtitle = [object objectForKey:@"location"]; 
        annotation.objectID = object.objectId; 

        [self.theMap addAnnotation:annotation]; 
       } 
      } 
     }]; 
    }]; 

    //[self.theMap reloadInputViews]; 
} 

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    static NSString *identifier = @"theLocation"; 
    if ([annotation isKindOfClass:[Annotation class]]) { 
     MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.theMap dequeueReusableAnnotationViewWithIdentifier:identifier]; 

     if (annotationView == nil) { 
      annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
     } else { 
      annotationView.annotation = annotation; 
     } 
     annotationView.enabled = YES; 
     //annotationView.canShowCallout = YES; 

     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(-40, -100, 100, 100)]; 
     imageView.contentMode = UIViewContentModeScaleAspectFit; 

     NSString *id = [(Annotation *)annotationView.annotation objectID]; 

     PFQuery *query = [PFQuery queryWithClassName:@"HomePopulation"]; 
     [query getObjectInBackgroundWithId:[NSString stringWithFormat:@"%@", id] block:^(PFObject *object, NSError *error) { 
      PFFile *file = [object objectForKey:@"imageFile"]; 
      [file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
       imageView.image = [UIImage imageWithData:data]; 
      }]; 
     }]; 
     annotationView.image = [UIImage imageNamed:@"pointer"]; 
     [annotationView addSubview:imageView]; 

     return annotationView; 
    } 
    return nil; 
} 

Annotation.h 
#import <Foundation/Foundation.h> 
#import <MapKit/MapKit.h> 
#import <Parse/Parse.h> 

@interface Annotation : NSObject <MKAnnotation> 

@property (nonatomic) CLLocationCoordinate2D coordinate; 
@property (nonatomic, copy) NSString *title; 
@property (nonatomic, copy) NSString *subtitle; 
@property (nonatomic, copy) NSString *objectID; 


@end 
+0

Что такое Я не мог найти в своей структуре, а также я не мог импортировать этот файл – TheMall

+0

, не могли бы вы дать мне пример кода, что вы сделали ...? означает образец проекта карты с изображениями. – TheMall

+1

Parse - это облачная служба, которую я использую в этом приложении. Я предлагаю вам взглянуть на эту ссылку: https://parse.com/products/ios#overview, где у вас есть вся информация, пошаговые руководства и документация, которые вам нужны. – zzzel

Смежные вопросы