使用没有显示引脚Parse.com [英] Pins not being shown using Parse.com
问题描述
我想销增加了几个位置我在类中的一个创造,这就是所谓的邻居。
I am trying to add pins to a couple of locations I created in one of my classes, which is called "Places".
到这些位置的关键是定义为places_coordinates。
The key to these locations is defined as "places_coordinates".
我设法安置这些引脚如下:
I tried to place those pins as follows:
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内的所有优惠,但我没有找到放标志物在它的方式。
My log is showing all offers inside the offersArray, but I am not finding a way of putting markers in it.
我也尝试了一些其他话题,但并没有真正得到它:
I also tried a couple of other topics, but did not really get it:
<一个href=\"http://stackoverflow.com/questions/23585584/adding-mapview-annotations-within-parse-query-returns-null-randomly\">Adding解析查询返回内的MapView注释空随机
最好的问候,
推荐答案
发生了什么事是,我的for循环不正确建立。
What was happening was that my for loop was not built correctly.
这应该是这样的:
...
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);
}
}
...
这篇关于使用没有显示引脚Parse.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!