Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 地图套件缩放问题_Ios_Mapkit_Cllocationmanager - Fatal编程技术网

Ios 地图套件缩放问题

Ios 地图套件缩放问题,ios,mapkit,cllocationmanager,Ios,Mapkit,Cllocationmanager,我有一个应用程序,它有一个带有位置PIN的地图,但我想更改它,以便放大用户的位置 默认情况下,它从坐标0、0开始(离开非洲海岸),但现在它在英国上,但我不能把它放大到街道级别。当我调整Delta设置时,它没有任何区别 这是我正在使用的代码 #import "FirstViewController.h" #import "MapPin.h" @implementation FirstViewController @synthesize map; @synthesize locationMana

我有一个应用程序,它有一个带有位置PIN的地图,但我想更改它,以便放大用户的位置

默认情况下,它从坐标0、0开始(离开非洲海岸),但现在它在英国上,但我不能把它放大到街道级别。当我调整
Delta
设置时,它没有任何区别

这是我正在使用的代码

#import "FirstViewController.h"
#import "MapPin.h"

@implementation FirstViewController

@synthesize map;
@synthesize locationManager , location;


-(void)addAnnotations{

    // Normally read the data for these from the file system or a Web service
    CLLocationCoordinate2D coordinate = {53.0670, -2.521};
    MapPin *pin = [[MapPin alloc]initWithCoordinates:coordinate
                                           placeName:@"Mr Shoe - Gents,Ladies,Kids"
                                         description:@"01270 626767, 123 Your Street, CW5 5NA"
                   ];

    [self.map addAnnotation:pin];

    [pin release];

    // Normally read the data for these from the file system or a Web service
    CLLocationCoordinate2D coordinate2 = {53.0659, -2.521};
    MapPin *pin2 = [[MapPin alloc]initWithCoordinates:coordinate2
                                            placeName:@"Veg-is-us - Fruit & veg"
                                          description:@"01270 626767, 123 Your Street, CW5 5NA"

                    ];

    [self.map addAnnotation:pin2];


    [pin2 release]; 

    CLLocationCoordinate2D coordinate3= {53.06879, -2.52195};
    MapPin *pin3= [[MapPin alloc]initWithCoordinates:coordinate3
                                            placeName:@"PC Centre Nantwich"
                                          description:@"01270 626767, 15c Beam street, CW5 5NA"

                    ];

    [self.map addAnnotation:pin3];


    [pin3 release]; 
}

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self) {
 // Custom initialization.
 }
 return self;
 }
 */


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
    [self addAnnotations];
        [self addAnnotations];


     [super viewDidLoad];
}
-(void) locationManager: (CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    location = newLocation.coordinate;
    //One location is obtained.. just zoom to that location

    MKCoordinateRegion region;
    region.center=location;
    //Set Zoom level using Span
    MKCoordinateSpan span;
    span.latitudeDelta=0.4;
    span.longitudeDelta=0.4;
    region.span=span;
    NSLog(@"map=%@", map);
    [map setRegion:region animated:TRUE];

}

/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations.
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end

viewDidLoad
中,此行没有任何作用:

[[CLLocationManager alloc] init];
编译器应该在该行给出警告,如“表达式结果未使用”


您需要将该代码的结果实际分配给
locationManager
变量,并且需要设置
delegate
,否则将不会调用delegate方法:

self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;


顺便说一下,在
viewDidLoad
中,您正在调用
[self addAnnotations]两次,我认为最好先调用
[super viewDidLoad]
而不是最后一次。

有人吗?这一定是一个简单的错误,但我看不出来,代码看起来不错。是否确定正在调用委托方法(在那里放置断点或NSLog)?在该委托方法中,就在setRegion行之前,放置
NSLog(@“map=%@”,map)并查看它打印的内容。你是否在你的应用程序的其他地方更新地图区域?@MDT这是我的代码,我试图输出到调试,但它似乎没有记录它,因为我升级了Xcode(旧的调试控制台工作正常),谢谢@Anna我整理了一下,它现在放大了,太棒了,非常感谢你帮我省去了更多的麻烦,然而,我现在已经失去了在地图上导航的能力,它是用橡皮筋拉回到中心的。有什么想法吗?每次用户位置更新时,didUpdateToLocation方法都会被调用,其中的代码会一直以用户为中心。要仅放大第一次更新,请调用
[manager stopUpdatengLocation]在该方法的末尾。