我在iPhone上使用MKMapView
创建一个地图应用程序。个zoomLevel和mapCenter中的MKMapView
我也顺利地找到我的current location
和zoom
在这一点上是这样的:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.mapView.delegate = self;
self.locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[self.mapView setShowsUserLocation:YES];
}
-(void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id<MKAnnotation> mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1550, 1550);
[self.mapView setRegion:region animated:YES];
}
,我想解决的问题是:
我对map
(此代码location
在viewDidLoad
):
CLLocationCoordinate2D location = [self getLocationFromAddressString:@"San Francisco, CA, United States"];
// location.latitude = 37.78608;
// location.longitude = -122.407398;
MapViewAnnotation *mapAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Store location" coordinate:location];
[self.mapView addAnnotation:mapAnnotation];
并且这是mapViewAnnotation:
@implementation MapViewAnnotation
@synthesize title = _title;
@synthesize coordinate = _coordinate;
- (id) initWithTitle:(NSString *) t coordinate:(CLLocationCoordinate2D) c {
self = [super init];
if(self) {
_title = t;
_coordinate = c;
}
return self;
}
@end
我想为这个location
和我current location
适当zoomLevel
和mapCenter
。
我可以使用MapController.zoomToSpan()
做成功的Android。我如何在iPhone Map中修复它?
它是某种硬编码。你有在Android中使用MapController.zoomToSpan()吗?事情是我想中心,放大我的当前位置和'CLLocationCoordinate2D位置',你的代码不帮我。 – Ali
我有什么'didAddAnnotationViews'方法?我应该在哪里使用你的方法? – Ali
哎交配其很容易只看到如果创建CLLocationCoordinate2D对象阵列存储你们两个位置,并在arrLocation添加此并调用LocationUpdate方法或viewWillAppear中的方法此方法..只是尝试使用它.. –