我正在尝试显示我的 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];