//// HMViewController.m// 04-MapKit02-显示特定位置和区域//// Created by apple on 14-8-7.// Copyright (c) 2014年 heima. All rights reserved.//#import "HMViewController.h"#import @interface HMViewController () @property (weak, nonatomic) IBOutlet MKMapView *mapView;- (IBAction)backToUserLocation;@end@implementation
HMViewController- (void)viewDidLoad{ [super viewDidLoad]; // [self.mapView setCenterCoordinate:<#(CLLocationCoordinate2D)#>]; // 设置地图显示的中心位置// CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(39, 116);// [self.mapView setCenterCoordinate:coordinate
animated:YES]; // 设置地图显示的区域// [self.mapView setRegion:<#(MKCoordinateRegion)#>];// CLLocationCoordinate2D center = CLLocationCoordinate2DMake(39, 116);// MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.1);// MKCoordinateRegion region = MKCoordinateRegionMake(center,
span);// [self.mapView setRegion:region animated:YES]; self.mapView.userTrackingMode = MKUserTrackingModeFollow; self.mapView.delegate = self;}#pragma mark - MKMapViewDelegate- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{//
[mapView setCenterCoordinate:userLocation.location.coordinate animated:YES]; CLLocationCoordinate2D center = userLocation.location.coordinate; MKCoordinateSpan span = MKCoordinateSpanMake(0.2509, 0.2256); MKCoordinateRegion region = MKCoordinateRegionMake(center,
span); [self.mapView setRegion:region animated:YES];}//- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated//{// NSLog(@"%f %f", mapView.region.span.latitudeDelta, mapView.region.span.longitudeDelta);//}- (IBAction)backToUserLocation
{ CLLocationCoordinate2D center = self.mapView.userLocation.location.coordinate; [self.mapView setCenterCoordinate:center animated:YES];}@end
04-MapKit02-显示特定位置和区域
最新推荐文章于 2018-04-26 14:07:20 发布