mapView上的位置

时间:2013-11-18 11:08:52

标签: ios mkmapview

我有一张地图,我想在我打开它时设置用户位置(蓝点)。我尝试了很多东西而且没有用。请帮助我

MKCoordinateRegion region;
region.center.latitude=BG_LATITUDE;
region.center.longitude=BG_LONGITUDE;
region.span.latitudeDelta=SPAN_VALUE;
region.span.longitudeDelta=SPAN_VALUE;
[self.mapView setRegion:region animated:YES];



NSMutableArray *annotations =[[NSMutableArray alloc]init];
//coordinate (for the annotation)
CLLocationCoordinate2D location;
mapAnnotation *ann;




location.latitude=MaB_LATITUDE;
location.longitude=MaB_LONGITUDE;
//annotation
ann = [[mapAnnotation alloc]init];
[ann setCoordinate:location];
ann.title=@"Main Branch";
[annotations addObject:ann];

2 个答案:

答案 0 :(得分:4)

你不需要编写如此多的代码行来显示蓝点,MKMapView本身包含一个名为“showUserLocation”的属性,必须将其设置为true才能在地图上显示蓝点。

self.mapView.showsUserLocation = TRUE;

它还会自动跟踪设备的位置。希望它会对你有所帮助。

答案 1 :(得分:1)

如果您想要在地图上显示用户位置

,请使用此选项
self.mapView.showsUserLocation = YES;
相关问题