在地图视图的中心显示一个别针

时间:2014-12-18 12:09:57

标签: ios objective-c

我需要在地图视图的中心显示一个位置的图钉。我有坐标,但它没有显示在中心。谢谢!

3 个答案:

答案 0 :(得分:2)

只需将location设置为地图视图中心坐标。

// Example location
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(37.79520324238053, -122.40283370018005);

// Drop a pin
MKPointAnnotation *startPin = [[MKPointAnnotation alloc] init];
startPin.coordinate = location;
startPin.title = @"Start";
[self.mapView addAnnotation:startPin];

[self.mapView setCenterCoordinate:location];

答案 1 :(得分:0)

[[self mapView] setCenterCoordinate:location animated:YES]; 

其中,location是CLLocationCoordinate2D的类型,它包含纬度和经度。

答案 2 :(得分:0)

 CLLocation *newLocation = locations.lastObject;
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(newLocation.coordinate,1000.0, 1000.0);
    [self.mapView setRegion:viewRegion animated:YES];
    self.mapView.showsUserLocation = YES;
    MKPointAnnotation *pointMap = [[MKPointAnnotation alloc] init];
    pointMap.coordinate = newLocation.coordinate;

- (void)mapView:(MKMapView *)mapView1 didAddAnnotationViews:(NSArray *)views
{
    NSLog(@"didAddAnnotationViews");
    for (MKAnnotationView *view in views)
    {
        if ([[view annotation] isKindOfClass:[MKUserLocation class]])
        {
            MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([[view annotation] coordinate] , 1000.0, 1000.0);
            [mapView1 setRegion:region animated:YES];
        }
    }

}

- (MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    NSLog(@"viewForAnnotation");
    if ([annotation isKindOfClass:[MKUserLocation class]])
    {
        return nil;
    }
        return nil;
}