gpt4 book ai didi

ios - 使用 Parse.com 未显示 Pins

转载 作者:行者123 更新时间:2023-11-29 02:33:41 24 4
gpt4 key购买 nike

我正在尝试将图钉添加到我在我的一个类(class)中创建的几个位置,这被称为“地点”。

这些位置的键被定义为“places_coordinates”。

我尝试按如下方式放置这些引脚:

View Controller.h

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

@interface ViewController : UIViewController<CLLocationManagerDelegate, MKMapViewDelegate>


@property (nonatomic, retain) CLLocationManager *locationManager;
@property(nonatomic, strong) MKPinAnnotationView *geoPointAnnotation;
@property(nonatomic, strong)MKPointAnnotation *annotation;
@property(nonatomic, strong)CLLocation *location;
@property (nonatomic, strong) PFObject *detailItem;
@property (weak, nonatomic) IBOutlet MKMapView *appleMap;


@end


ViewController.m


- (void)viewDidLoad {

[super viewDidLoad];

if (nil == self.locationManager){

self.locationManager = [[CLLocationManager alloc] init];

self.locationManager.delegate = self;

//Configure Accuracy depending on your needs, default is kCLLocationAccuracyBest

self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;

// Set a movement threshold for new events.

self.locationManager.distanceFilter = 500; // meters

[self.locationManager startUpdatingLocation];

[self.locationManager requestWhenInUseAuthorization];

[self.locationManager requestAlwaysAuthorization];

}



self.appleMap.delegate = self;

// Map will show current location

self.appleMap.showsUserLocation = YES;


// Maps' opening spot

self.location = [self.locationManager location];

CLLocationCoordinate2D coordinateActual = [self.location coordinate];

// Map's zoom

MKCoordinateSpan zoom = MKCoordinateSpanMake(0.010, 0.010);

// Create a region

MKCoordinateRegion region = MKCoordinateRegionMake(coordinateActual, zoom);

// Method which sets exibition method

[self.appleMap setRegion:region animated:YES];

//Map's type

self.appleMap.mapType = MKMapTypeStandard;


}


#pragma mark - Location Manager Callbacks



-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{


[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {

if (!error) {

// Create Object

PFObject *offersLocation = [PFObject objectWithClassName:@"Places"];

//Create a point for markers

PFGeoPoint *offersPoint = offersLocation[@"places_coordinate"];

// Check current Location

NSLog(@"%@", offersPoint);

// Create a query for Places of interest near current location

PFQuery *query = [PFQuery queryWithClassName:@"Places"];

[query whereKey:@"places_coordinate" nearGeoPoint:geoPoint withinKilometers:5.0];

NSLog(@"Query: %@",query);

// Limit the query

query.limit = 10;

// Store objects in the array
NSArray *offersArray = [query findObjects];

NSLog(@"Array: %@",offersArray);

if (!error) {

for (query in offersArray) {



self.annotation = [[MKPointAnnotation alloc]

init];

CLLocationCoordinate2D coord = {offersPoint.latitude, offersPoint.longitude};

self.annotation.coordinate = coord ;

[self.appleMap addAnnotation:self.annotation];

NSLog(@"Annotation: %@",self.annotation);

}

}

}

}];

}



#pragma mark - MKMapViewDelegate

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{

static NSString *MapViewAnnotationIdentifier = @"places_coordinate";

MKPinAnnotationView *pinOffers = [[MKPinAnnotationView alloc] initWithAnnotation:self.annotation reuseIdentifier:MapViewAnnotationIdentifier];

pinOffers.pinColor = MKPinAnnotationColorRed;

pinOffers.canShowCallout = YES;

pinOffers.animatesDrop = YES;

return pinOffers;

}

我的日志显示了 offersArray 中的所有优惠,但我没有找到在其中放置标记的方法。

我还尝试了其他几个主题,但并没有真正理解:

how to add multiple pin at the same lat/long

Adding mapview annotations within parse query returns null randomly

最好的问候,

最佳答案

发生的事情是我的 for 循环没有正确构建。

应该是这样的:

...
if (!error) {
for (PFObject *offerObject in offersArray) {


PFGeoPoint *offerPoint = [offerObject objectForKey:@"coordenadas"];

MKPointAnnotation *geoPointAnnotation = [[MKPointAnnotation alloc]
init];

geoPointAnnotation.coordinate = CLLocationCoordinate2DMake(offerPoint.latitude, offerPoint.longitude);

[self.appleMap addAnnotation:geoPointAnnotation];

NSLog(@"Annotation: %@",geoPointAnnotation);

}
}

...

关于ios - 使用 Parse.com 未显示 Pins,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26610048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com