iphone:MKMapView

在iphone上实现地图并不难。在Frameworks中加入MapKit.framework,要对mapView做相应的操作时要添加一个outlet,记得#import<MapKit/MapKit.h>即可。

可参考博客 ios利用MKMapView实现简单的地图

显示当前自己位置:利用MKMapView显示自己当前位置的地图


加入CoreLocation.framework,

VC遵循

<CLLocationManagerDelegate>

 mapView.showsUserLocation=YES; 

    CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器 
    locationManager.delegate=self;//设置代理 
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别 
    locationManager.distanceFilter=1000.0f;//设置距离筛选器 
    [locationManager startUpdatingLocation];//启动位置管理器 
    MKCoordinateSpan theSpan; 
    //地图的范围 越小越精确 
    theSpan.latitudeDelta=0.05; 
    theSpan.longitudeDelta=0.05; 
    MKCoordinateRegion theRegion; 
    theRegion.center=[[locationManager location] coordinate]; 
    theRegion.span=theSpan; 
    [mapView setRegion:theRegion]; 
    [locationManager release];

在xcode中设置模拟器的位置,参照:

xcode4.2 模拟器定位 。xcode4.2 添加GPX文件。手工指定位置。 

给当前位置加大头针:

使用的是MKMapViewDelegate的mapView:viewForAnnotation:方法

  - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
    {
        MKPinAnnotationView *pinView = nil;

            static NSString *defaultPinID = @"com.invasivecode.pin";
            pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
            if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                              initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
            pinView.pinColor = MKPinAnnotationColorRed;
            pinView.canShowCallout = YES;
            pinView.animatesDrop = YES;
             [mapView.userLocation setTitle:@"欧陆经典"];
           [mapView.userLocation setSubtitle:@"vsp"];
         return pinView;
    }

参照:http://www.cocoachina.com/iphonedev/sdk/2010/1020/2216.html

MKAnnotationView 有一个image属性,应该可以改掉大头针的图形,改为flag?!

 

http://www.helmsmansoft.com/index.php/archives/980罗盘功能

 

//设置经纬度

CLLocationCoordinate2D coord = {39.904667,116.408198};

//设置显示范围

MKCoordinateSpan span = MKCoordinateSpanMake(0.4,0.4);

//设置地图显示的中心和范围

MKCoordinateRegion region = MKCoordinateRegionMake(coord,span);

//根据设置的信息进行显示

[mapView setRegion region animated:NO];

[mapView sizeToFit];

原文地址:https://www.cnblogs.com/mybkn/p/2499896.html