0

JSON ファイルからピンを表示しようとしていますが、ピンが表示されません。助けていただければ幸いです。また、ボタンは別の JSON ページを呼び出します。

my code for mapview.m:

- (void)viewDidLoad
{
[super viewDidLoad];

NSURL *url = [NSURL URLWithString:@"https://w1281595.users.ecs.westminster.ac.uk/shops.php"];
NSData *data = [NSData dataWithContentsOfURL:url];

NSError *error;
NSArray *shoparray = [NSJSONSerialization JSONObjectWithData:data
                                                     options:0
                                                       error:&error];
if (error != nil)
{
}

CLLocationCoordinate2D location;                         
NSMutableArray *newAnnotations = [NSMutableArray array]; 
MKPointAnnotation *newAnnotation;                       

for (NSDictionary *dictionary in shoparray)
{
        location.longitude = [dictionary[@"Longitude"] doubleValue];
        location.latitude = [dictionary[@"Latitude"] doubleValue];

        newAnnotation = [[MKPointAnnotation alloc] init];
        newAnnotation.title = dictionary[@"Name"];
        newAnnotation.coordinate = location;      

    }

    [self.mapview addAnnotations:newAnnotations];
4

1 に答える 1

0

あなたのループはnewAnnotation毎回を作成します。次に、マップに呼び出された配列を追加しnewAnnotationsます。newAnnotationsしかし、配列に何かを入れるのを忘れています。

于 2013-04-21T07:24:24.160 に答える