0

我一直在阅读其他一些关于注释中披露按钮的帖子,但我找不到任何有用的东西。基本上,我从我从 JSON 解析的位置向地图添加注释。我想为这些注释添加一个披露按钮,当按下披露按钮时,我想在下一个 viewController 中加载特定于该位置的 JSON 信息。到目前为止,这是我的代码,它显示了每个位置的注释。视图控制器.m

#import "ViewController.h"
#import "Annotation.h"
#import "City.h"
@interface ViewController ()


@end
#define getDatalURL @"http://www.club-hop.com/apptest.php"

@implementation ViewController
@synthesize mapView,jsonArray,citiesArray;


- (void)viewDidLoad
{
[super viewDidLoad];
[self retrieveData];


City * cityObject;

// load external page into UIWebView
NSMutableArray * locations= [[NSMutableArray alloc]init];
CLLocationCoordinate2D location;
Annotation * myAnn;

for(int u=0; u<citiesArray.count;u++){
cityObject=[citiesArray objectAtIndex:u];
myAnn=[[Annotation alloc]init];
NSNumber *aLat= cityObject.Latitude;
NSNumber *aLon= cityObject.Longitude;

double lat = [aLat doubleValue];
double lon = [aLon doubleValue];

location.latitude= lat;
location.longitude=lon;
myAnn.coordinate = location;
myAnn.title=cityObject.clubName;
myAnn.subtitle=cityObject.cityName;
[locations addObject:myAnn];}

[self.mapView addAnnotations:locations];


}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}



//class methods
-(void) retrieveData{
NSURL * url= [NSURL URLWithString:getDatalURL];
NSData * data= [NSData dataWithContentsOfURL:url];
jsonArray= [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

//setup cities array
citiesArray=[[NSMutableArray alloc]init];

for(int i=0; i<jsonArray.count;i++){
    NSString * cID= [[jsonArray objectAtIndex:i] objectForKey:@"id"];
    NSString * cName= [[jsonArray objectAtIndex:i] objectForKey:@"cityName"];
    NSString * cCountry= [[jsonArray objectAtIndex:i] objectForKey:@"cityCountry"];
    NSString * cLine= [[jsonArray objectAtIndex:i] objectForKey:@"clubLine"];
    NSString * clName= [[jsonArray objectAtIndex:i] objectForKey:@"clubName"];
    NSNumber * cLatitude= [[jsonArray objectAtIndex:i] objectForKey:@"Latitude"];
    NSNumber * cLongitude= [[jsonArray objectAtIndex:i] objectForKey:@"Longitude"];

    [citiesArray addObject:[[City alloc]initWithCityName:cName andCityCountry:cCountry      andClubName:clName andClubLine:cLine andLatitude:cLatitude andLongitude:cLongitude andCityId:cID]];

}

}

视图控制器.h

#import <UIKit/UIKit.h>
#import <Mapkit/Mapkit.h>

@interface ViewController : UIViewController <MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (nonatomic, strong) NSMutableArray * jsonArray;
@property (nonatomic, strong) NSMutableArray * citiesArray;

-(void) retrieveData;


@end

注释.m

#import "Annotation.h"

@implementation Annotation
@synthesize coordinate,title,subtitle;

@end

注释.h

#import <Foundation/Foundation.h>
#import <Mapkit/Mapkit.h>
@interface Annotation : NSObject
@property(nonatomic,assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy) NSString * title;
@property(nonatomic, copy) NSString * subtitle;

@end
4

1 回答 1

0

这里是可能对你有帮助的链接 MapCallout From apple

下载源代码并检查桥接

于 2014-04-07T10:56:24.933 回答