mapView use method
1 。地圖編程接口;
2. 可規划的路線;
3. 設置書簽標記;
4.周邊查找服務。
結構 表示 地圖上一個點,一個矩形區域,一個大小。
手機位置服務,導航
typedef struct
{
CLLocationDegrees latitudeDelta;
CLLocationDegrees longitudeDelta;
} MKCoordinateSpan;
typedef struct{
CLLocationCoordinate2D center;
MKCoordinateSpan span;
}MKCoordinateRegion;
1 .h file
// Created by denny chen on 12-7-8.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapKitViewViewController : UIViewController
{
MKMapView *MKMapView;
}
@property (retain, nonatomic) IBOutlet MKMapView *mymapkit;
2 .m file
@implementation MapKitViewViewController
@synthesize mymapkit;
- (void)viewDidLoad
{
[super viewDidLoad];
//set display jing wei du
CLLocationCoordinate2D center;
center.latitude=40.029915;
center.longitude=116.347082;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
MKCoordinateRegion region={center,span};
//set map center location
[self.mymapkit setRegion:region];
}
- (void)viewDidUnload
{
[self setMymapkit:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (void)dealloc {
[mymapkit release];
[super dealloc];
}
3 create myAnnotation.h file
#import <Foundation/Foundation.h>
#import <MAPkit/Mapkit.h>
@interface myAnnotation : NSObject <MKAnnotation>
@end
4 create myAnnotation.m file
#import "myAnnotation.h"
@implementation myAnnotation
-(CLLocationCoordinate2D) coordinate
{
CLLocationCoordinate2D center;
center.latitude=40.029915;
center.longitude=116.347082;
return center;
}
-(NSString *) title
{
return @"北京大學";
}
-(NSString *) subtitle
{
return @"你所查尋的位置";
}
@end
4 run reslut