Я пытаюсь добавить булавки в пару мест, которые я создал в одном из моих классов, который называется «Места».Штыри не отображаются с помощью Parse.com
Ключ к этим местоположениям определяется как «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
С наилучшими пожеланиями,
Я думаю, что я могу помочь - просто уточнить, хотя, вы не видите какие-либо контактов на вашей карте, и вы хотите, чтобы ваши пальцы, чтобы показать на карте, право ? –
Привет @RyanKreager, спасибо за ваш ответ. Да, я могу видеть только текущее местоположение. Других я не могу. –