Este exemplo ilustra como embedar, ou exibir um MapView no iPhone através do aplicativo SDK UIView.
Para embedar um mapa no seu iPhone,
apenas siga os passos a seguir:
1. Crie um novo projeto (ViewBased application).
2. Importe o MapKit no arquivo do cabeçalho:
#import <MapKit/MapKit.h>
Também adicione o MapKit.framework sob a pasta de recursos dos
frameworks existentes.
3. No mesmo arquivo do cabeçalho viewController, cheme <MKMapViewDelegate> e defina o MKMapView *myMapView; sintetize e libere o objeto myMapView dentro do arquivo de implementação.
4. No arquivo viewcontroller.xib, adicione o map view no UIView e o
conecte com o objeto correspondente no dono do arquivo. Em seguida, veja o
código abaixo:
Header
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface myMapViewController : UIViewController <MKMapViewDelegate> {
IBOutlet MKMapView* myMapView;
}
@property (nonatomic, retain) IBOutlet MKMapView* myMapView;
-(void)displayMYMap;
@end
Implementation
#import "myMapViewController.h"
@implementation myMapViewController
@synthesize myMapView;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
myMapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
myMapView.delegate=self;
[self.view addSubview:myMapView];
[NSThread detachNewThreadSelector:@selector(displayMYMap) toTarget:self withObject:nil];
}
-(void)displayMYMap
{
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
CLLocationCoordinate2D location;
location.latitude = 22.569722 ;
location.longitude = 88.369722;
region.span=span;
region.center=location;
[myMapView setRegion:region animated:TRUE];
[myMapView regionThatFits:region];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)dealloc {
[super dealloc];
[myMapView release];
}
@end
Construa o aplicativo para exibir o map view no UIView. Ele deve se parecer com a imagem abaixo:

Download do código do exemplo do MapView para iPhone
?
Texto original disponível em http://www.roseindia.net/tutorial/iphone/examples/MapViewExampleiniPhone.html








