MKMapView未在设备上显示

时间:2011-09-02 06:51:49

标签: iphone devise mkmapview

我有一点问题,我不知道为什么会这样。

我的地图视图在模拟器中很好,但在真实设备上我只看到灰色区域上的图钉和“google”徽标。这就像图像无法加载,看起来就像你放大并等待视图在广场周围绘制。

这是我的代码,我将不胜感激任何帮助

#import "Maps.h"
#import "RootViewController.h"


@implementation AddressAnnotation

@synthesize coordinate;
-(NSString *) subtitle{
    return @"327 Anzac Parade, Wodonga, Victoria, Australia";
}
-(NSString *) title{
    return @"Blazing Stump";
}
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{
    coordinate = c;
    NSLog(@"%f,%f",c.latitude, c.longitude);
    return self;
}

@end


@implementation Maps

-(CLLocationCoordinate2D) addressLocation{

    NSString *locationString =  [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://maps.google.com/maps/geo?q=327%20Anzac%20Parade,%20Wodonga,%20Victoria,%20Australia&output=csv&key=ABQIAAAAZs2zFXiuKBFeLpPgSfgMjBTHxw17-t8q3X3AgrE9NufATyE8MRRmwlyLMPtOSzliJQntEtaZ7T-Rww"]
                                                         encoding:NSUTF8StringEncoding error:nil];
    NSArray *listItems = [locationString componentsSeparatedByString:@","];

    double latitude = -36.139226;
    double longitude = 146.911454;
    if ([listItems count] >=4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]){
        latitude = [[listItems objectAtIndex:2] doubleValue];
        longitude = [[listItems objectAtIndex:3] doubleValue];
    }else {
        //some error
    }
    CLLocationCoordinate2D  location;
    location.latitude = latitude;
    location.longitude = longitude;
    return location;

}
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
    MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
    annView.pinColor = MKPinAnnotationColorGreen;
    annView.animatesDrop = TRUE;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}

- (void)viewDidLoad {
    MKCoordinateRegion region;
    MKCoordinateSpan span;
    span.latitudeDelta=0.2;
    span.longitudeDelta=0.2;

    CLLocationCoordinate2D location = [self addressLocation];
    region.span=span;
    region.center=location;

    if(addAnnotation != nil) {
        [mapView removeAnnotation:addAnnotation];
        [addAnnotation release];
        addAnnotation = nil;
    }

    addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:location];
    [mapView addAnnotation:addAnnotation];

    [mapView setRegion:region animated:TRUE];
    [mapView regionThatFits:region];
    //[mapView selectAnnotation:mLodgeAnnotation animated:YES];
    [super viewDidLoad];
}
- (void)dealloc {
    [super dealloc];
    [viewController release];

}

1 个答案:

答案 0 :(得分:0)

您确定已设置地图delgate吗?确保将委托添加到标题中,并在视图上加载mapkit.delegate = self;