Ios 地图套件帮助。Can';我不能让我的位置先出现
我想开发一个地图,显示我的位置,并在地图上有其他位置的引脚 我已经得到了地图显示和引脚显示了,它也找到了我,但它没有放大到我的位置第一。我怎样才能让它先显示我的位置?当我打开地图视图时,它只显示我输入代码的最后一个pin。 这是我的密码 地图视图.hIos 地图套件帮助。Can';我不能让我的位置先出现,ios,geolocation,mapkit,cllocationmanager,Ios,Geolocation,Mapkit,Cllocationmanager,我想开发一个地图,显示我的位置,并在地图上有其他位置的引脚 我已经得到了地图显示和引脚显示了,它也找到了我,但它没有放大到我的位置第一。我怎样才能让它先显示我的位置?当我打开地图视图时,它只显示我输入代码的最后一个pin。 这是我的密码 地图视图.h #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interface mapview : UIViewController { MKMapView *ma
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface mapview : UIViewController {
MKMapView *mapview1;
}
@property (nonatomic, retain) IBOutletMKMapView *mapview1;
-(IBAction)setMap:(id)sender;
-(IBAction)getlocation;
@end
您已经设置了showsUserLocation,但是如果您阅读Apple文档,您将看到该函数只打开蓝点,它不会缩放或平移视图。"http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/occ/instp/MKMapView/showsUserLocation 您要做的是将用户跟踪模式设置为userfollows 其他代码提示:
- 将所有这些位置放在一个数组中并在其上循环,不要一次创建一个这样的位置
- 不要在地图上为您创建的每个区域设置区域。您正在尝试让地图放大用户,并且每个设置区域都会更改地图的查看位置。无论如何,只有最后一个设置区域会有任何效果
- 您不需要仅仅为了获取注释的坐标而创建区域
mapview1.userTrackingMode=MKUserTrackingModeFollow
ref:
#import "mapview.h"
#import "NewClass.h"
@implementation mapview
@synthesize mapview1;
-(IBAction)getlocation {
mapview1.showsUserLocation = YES;
}
-(IBAction)setMap:(id)sender {
switch (((UISegmentedControl *) sender).selectedSegmentIndex) {
case 0:
mapview1.mapType = MKMapTypeStandard;
break;
case 1:
mapview1.mapType = MKMapTypeSatellite;
break;
case 2:
mapview1.mapType = MKMapTypeHybrid;
break;
default:
break;
}
}
-(void)viewDidLoad {
[super viewDidLoad];
[mapview1 setMapType:MKMapTypeStandard];
[mapview1 setZoomEnabled:YES];
[mapview1 setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
region.center.latitude = 39.956907;
region.center.longitude = -75.610229;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region animated:YES];
NewClass *ann = [[NewClass alloc] init];
ann.title = @"Vigil Location";
ann.subtitle = @"Planned Parenthood of Chester County";
ann.coordinate = region.center;
[mapview1 addAnnotation:ann];
MKCoordinateRegion region1 = { {0.0, 0.0 }, {0.0, 0.0 } };
region1.center.latitude = 40.042819;
region1.center.longitude = -75.373776;
region1.span.longitudeDelta = 0.01f;
region1.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region1 animated:YES];
NewClass *ann1 = [[NewClass alloc] init];
ann1.title = @"Vigil Location";
ann1.subtitle = @"Planned Parenthood of Bryn Mawr";
ann1.coordinate = region1.center;
[mapview1 addAnnotation:ann1];
MKCoordinateRegion region2 = { {0.0, 0.0 }, {0.0, 0.0 } };
region2.center.latitude = 40.18295;
region2.center.longitude = -75.450163;
region2.span.longitudeDelta = 0.01f;
region2.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region2 animated:YES];
NewClass *ann2 = [[NewClass alloc] init];
ann2.title = @"Vigil Location";
ann2.subtitle = @"Planned Parenthood Collegeville";
ann2.coordinate = region2.center;
[mapview1 addAnnotation:ann2];
MKCoordinateRegion region3 = { {0.0, 0.0 }, {0.0, 0.0 } };
region3.center.latitude = 40.120772;
region3.center.longitude = -75.118181;
region3.span.longitudeDelta = 0.01f;
region3.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region3 animated:YES];
NewClass *ann3 = [[NewClass alloc] init];
ann3.title = @"Vigil Location";
ann3.subtitle = @"Abington Memorial Hospital";
ann3.coordinate = region3.center;
[mapview1 addAnnotation:ann3];
MKCoordinateRegion region4 = { {0.0, 0.0 }, {0.0, 0.0 } };
region4.center.latitude = 39.95361;
region4.center.longitude = -75.15267;
region4.span.longitudeDelta = 0.01f;
region4.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region4 animated:YES];
NewClass *ann4 = [[NewClass alloc] init];
ann4.title = @"Vigil Location";
ann4.subtitle = @"Philadelphia Women's Center";
ann4.coordinate = region4.center;
[mapview1 addAnnotation:ann4];
MKCoordinateRegion region5 = { {0.0, 0.0 }, {0.0, 0.0 } };
region5.center.latitude = 39.910566;
region5.center.longitude = -75.014111;
region5.span.longitudeDelta = 0.01f;
region5.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region5 animated:YES];
NewClass *ann5 = [[NewClass alloc] init];
ann5.title = @"Vigil Location";
ann5.subtitle = @"Cherry Hill Women's Center";
ann5.coordinate = region5.center;
[mapview1 addAnnotation:ann5];
MKCoordinateRegion region6 = { {0.0, 0.0 }, {0.0, 0.0 } };
region6.center.latitude = 39.74285;
region6.center.longitude = -75.550838;
region6.span.longitudeDelta = 0.01f;
region6.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region6 animated:YES];
NewClass *ann6 = [[NewClass alloc] init];
ann6.title = @"Vigil Location";
ann6.subtitle = @"Planned Parenthood of Wilmington";
ann6.coordinate = region6.center;
[mapview1 addAnnotation:ann6];
MKCoordinateRegion region7 = { {0.0, 0.0 }, {0.0, 0.0 } };
region7.center.latitude = 40.03754;
region7.center.longitude = -76.300828;
region7.span.longitudeDelta = 0.01f;
region7.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region7 animated:YES];
NewClass *ann7 = [[NewClass alloc] init];
ann7.title = @"Vigil Location";
ann7.subtitle = @"Planned Parenthood of Lancaster";
ann7.coordinate = region7.center;
[mapview1 addAnnotation:ann7];
MKCoordinateRegion region8 = { {0.0, 0.0 }, {0.0, 0.0 } };
region8.center.latitude = 40.333819;
region8.center.longitude = -75.93019;
region8.span.longitudeDelta = 0.01f;
region8.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region8 animated:YES];
NewClass *ann8 = [[NewClass alloc] init];
ann8.title = @"Vigil Location";
ann8.subtitle = @"Planned Parenthood of Reading";
ann8.coordinate = region8.center;
[mapview1 addAnnotation:ann8];
MKCoordinateRegion region9 = { {0.0, 0.0 }, {0.0, 0.0 } };
region9.center.latitude = 40.67246;
region9.center.longitude = -75.375397;
region9.span.longitudeDelta = 0.01f;
region9.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region9 animated:YES];
NewClass *ann9 = [[NewClass alloc] init];
ann9.title = @"Vigil Location";
ann9.subtitle = @"Planned Parenthood of Allentown";
ann9.coordinate = region9.center;
[mapview1 addAnnotation:ann9];
MKCoordinateRegion region10 = { {0.0, 0.0 }, {0.0, 0.0 } };
region10.center.latitude = 39.952384;
region10.center.longitude = -76.7253;
region10.span.longitudeDelta = 0.01f;
region10.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region10 animated:YES];
NewClass *ann10 = [[NewClass alloc] init];
ann10.title = @"Vigil Location";
ann10.subtitle = @"Planned Parenthood of York";
ann10.coordinate = region10.center;
[mapview1 addAnnotation:ann10];
}
- (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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end