【问题标题】:map with photos like Instagram Photo Map带有照片的地图,例如 Instagram 照片地图
【发布时间】:2014-05-03 12:05:08
【问题描述】:

我正在尝试使用类似于 Instagram 的照片地图的照片创建地图。

照片地图: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];
                }
            }
        }];
    }];

任何帮助表示赞赏。 马尔科

【问题讨论】:

  • 具体的问题或疑问是什么?
  • 如何将图像(从 Parse 加载)添加到注释中,如上面的屏幕截图所示?

标签: ios mkmapview


【解决方案1】:

借助本次讨论:Custom annotations with same image

我想出了这个:

代码如下:

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

【讨论】:

  • 什么是 我在我的框架中找不到,也无法导入该文件
  • 你愿意给我你所做的示例代码吗...?表示带有图像的地图示例项目。
  • Parse 是我在这个应用程序中使用的云服务。我建议您查看此链接:parse.com/products/ios#overview,您可以在其中获得所需的所有信息、分步指南和文档。
  • 谢谢百万兄弟.. 它对我很有帮助... 还有一件事你想建立一个专业的关系吗?如果你不介意的话,你愿意给我你的 Facebook 链接吗?我也是 iOS 应用开发的新手。
  • 对不起,我不使用 Facebook。在 devxhkl@outlook.com 上给我写一封邮件,让我们看看我们能做些什么:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-20
相关资源
最近更新 更多