Вывести координаты словаря

Рейтинг: 0Ответов: 1Опубликовано: 09.04.2015

Собственно сам вопрос, как отправить координаты и название в словаре и после этого использовать их в CLLocationCoordinate2D? Код который их отправляет

    -(void)setupArray{
    self.myLocationManager = [[CLLocationManager alloc] init];
    self.myLocationManager.delegate = self;
    [self.myLocationManager startUpdatingLocation];
    CLLocation *startLocation = self.myLocationManager.location;
    CLLocation *location2 = [[CLLocation alloc] initWithLatitude:60.050043 longitude:30.345783];
    CLLocation *location3 = [[CLLocation alloc] initWithLatitude:60.040000 longitude:30.323994];
    CLLocation *location4 = [[CLLocation alloc] initWithLatitude:60.037389 longitude:30.322094];
    CLLocation *location5 = [[CLLocation alloc] initWithLatitude:60.037329 longitude:30.322014];
    float betweenDistance=[startLocation distanceFromLocation:location2];
    float betweenDistance3=[startLocation distanceFromLocation:location3];
    float betweenDistance4=[startLocation distanceFromLocation:location4];
     float betweenDistance5=[startLocation distanceFromLocation:location5];

    [GMSServices provideAPIKey:@"###"];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:59.93 longitude:30.35 zoom:9];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.settings.compassButton = YES;
    mapView_.settings.myLocationButton = YES;
    //mapView_.settings.myLocationButton = YES;
    //mapView_.userInteractionEnabled = YES;
    mapView_.frame = CGRectMake(0, 0, 200, 200);
    //mapView_.center = self.view.center;
    [self.scrollView addSubview:mapView_];
cellIdentifier = @"rowCell";
    states = [[NSMutableDictionary alloc]init];
    CLLocationCoordinate2D coordicate = (CLLocationCoordinate2D){.latitude=60.050043, .longitude=60.050043};
    states[@"Michigan"] = @{ @"string": [NSString stringWithFormat:@"Distance is %f km", (betweenDistance / 1000)],
                             @"coordinate": @{ @"lat": @(coordicate.latitude),
                                               @"lng": @(coordicate.longitude) }};
datasource = [states allKeys];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

И как я их пытаюсь получить

    - (void)viewDidLoad
{
    [super viewDidLoad];
    stateLabel.text = state;
    capitalLabel.text = capital;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(print_Message)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(print_Message)];
    [GMSServices provideAPIKey:@"###"];
    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:59.93 longitude:30.35 zoom:12];
    mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
    mapView_.settings.compassButton = YES;
    mapView_.settings.myLocationButton = YES;
    //mapView_.settings.myLocationButton = YES;
    //mapView_.userInteractionEnabled = YES;
    mapView_.frame = CGRectMake(0, 70, 320, 400);
    mapView_.center = self.view.center;
    [self.view addSubview:mapView_];
    // Получение координат из словаря
    NSDictionary *coordinateInfo = state[@"Michigan"][@"coordinate"];
    CLLocationCoordinate2D coordicateFromDictionry = (CLLocationCoordinate2D){.latitude=[coordinateInfo[@"lat"] doubleValue], .longitude=[coordinateInfo[@"lng"] doubleValue]};
CLLocationCoordinate2D position4 = CLLocationCoordinate2DMake(59.934673, 30.330702);
    GMSMarker *london4 = [GMSMarker markerWithPosition:position4];
    london4.title = @"Заголовок";
    london4.snippet = @"описание";
    london4.map = mapView_;
}

Но компилятор ругается на строку

NSDictionary *coordinateInfo = state[@"Michigan"][@"coordinate"];

Пишет что expected method to read dictionary element not find on object of tipe NSString

И ещё такой вопрос: мне нужно будет передавать координаты не одного словаря а нескольких, как мне организовать это? Т.е. изначально было такая попытка,(каждый словарь выводиться сначала в uitable и при нажатии на cell уже данные выбранного словаря отправляются на карту)

[states setObject:@"60.050043, 30.345783" forKey:[NSString stringWithFormat:@"Distance is %f km", (betweenDistance3 / 1000)] ];
[states setObject:@"61.050043, 30.345783" forKey:[NSString stringWithFormat:@"Distance is %f km", (betweenDistance4 / 1000)] ];
[states setObject:@"62.050043, 30.345783" forKey:[NSString stringWithFormat:@"Distance is %f km", (betweenDistance5 / 1000)] ];

потом то что вывидите выше, но координаты так толком не передались.

Ответы

Ответов пока нет.