Попытка показать местоположение пользователя на Mapkit, самая раздражающая вещь когда-либо. Кто-нибудь протянуть руку? - PullRequest
0 голосов
/ 26 ноября 2010

Я следую этому руководству (http://icodeblog.com/2009/12/21/introduction-to-mapkit-in-iphone-os-3-0/) при добавлении mapkit и аннотаций в приложение. Однако я серьезно борюсь с расположением пользователя. Я новичок в xcode, поэтому не совсем уверен, что делатьЗатем я попробовал вариант Тони:

step one: add the CoreLocation framework to the project.

Step two: add this function to the iCodeMapViewController.m:


- (void)setCurrentLocation:(CLLocation *)location {
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}};
region.center = location.coordinate;
region.span.longitudeDelta = 0.15f;
region.span.latitudeDelta = 0.15f;
[self.mapView setRegion:region animated:YES];
}

step three: add this code to the ViewForAnnotation Method:


if (annotation != mapView.userLocation) {
//the rest of the ViewForAnnotation code goes here
}else{
CLLocation *location = [[CLLocation alloc]
initWithLatitude:annotation.coordinate.latitude
longitude:annotation.coordinate.longitude];
[self setCurrentLocation:location];
} 

Но когда я иду на сборку, мне это не нравится.

Я также пробовал этот вариант:

    -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{
 if ([annotation isKindOfClass:MKUserLocation.class]) return nil;
        //rest of code
}

Синяя точка показывает, мои пользовательские аннотации показывают, но приложение падает, когда я пытаюсь прокрутить таблицу. Отладчик не помогает, но останавливается на этом утверждении.

Может кто-нибудь помочь?Примеры кода тоже? Я думаю, что ответ на этот пост может быть полезным для ряда людей, также борющихся с mapkit.

Приветствия

Ответы [ 2 ]

1 голос
/ 12 декабря 2010

У меня была такая же проблема, но мне удалось ее решить. В cellForRowAtIndexPath я сделал это:


NSMutableArray *annotations = [[NSMutableArray alloc] init];
    if(indexPath.section == 0)
    {
        for(MinuAsukohad *annotation in [mapView annotations])
        {
            if(![annotation isKindOfClass:[MKUserLocation class]])
            {  
            if([annotation annotationType] == MinuAsukohadTypeInterest)
                {
                [annotations addObject:annotation];
                }
            }
        }
        cell.textLabel.text = [[annotations objectAtIndex:indexPath.row] title];
    }

Вы просто должны повторить это для всех разделов.

0 голосов
/ 27 ноября 2010

Звучит так, как будто вы пытаетесь включить свое текущее местоположение в качестве одной из ячеек в таблице ... посмотрите на свою консоль и дайте нам вывод при возникновении сбоя.

...