1

我的情节提要上有一个 MKMapView,当我转到情节提要时,只是加载默认视图,而不是规格已设置的经纬度和跨度,但不会缩放到我正在寻找的位置。

在此处输入图像描述

这是.h

//
//  ContactViewController.h


#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface ContactViewController : UIViewController

@property (weak, nonatomic) IBOutlet MKMapView *myMapView;

@end

这是.m

//
//  ContactViewController.m


#import "ContactViewController.h"


@interface ContactViewController ()

@end

// define long and lat of location
#define map_long 42.877391;
#define map_lat -80.734766;

// define span
#define map_span 0.05f;



@implementation ContactViewController
@synthesize myMapView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}



- (void)viewDidLoad
{
    //[super viewDidLoad];

    MKCoordinateRegion myregion;
    CLLocationCoordinate2D mycenter;

    mycenter.latitude = map_lat;
    mycenter.longitude = map_long;

    MKCoordinateSpan myspan;
    myspan.latitudeDelta = map_span;
    myspan.longitudeDelta = map_span;


    myregion.center = mycenter;
    myregion.span = myspan;
    // Do any additional setup after loading the view.

    [myMapView setRegion:myregion animated:YES];
    [myMapView setCenterCoordinate:mycenter animated:YES];

}

@end
4

1 回答 1

0

你没有分配任何东西给myCenter.

您应该使用以下内容创建您的区域:

 MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(yourCenterCoord, 250, 250);

(其中第一个参数是您的CLLocationCoordinate2D中心变量,另外两个是距中心的纬度和经度距离)

于 2013-09-18T22:52:25.657 回答