新聞中心
iOS地圖開發(fā)
簡介
IOS地圖幫助我們定位位置,IOS地圖使用 MapKit 框架。

我們提供的服務(wù)有:網(wǎng)站設(shè)計制作、網(wǎng)站設(shè)計、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、商水ssl等。為上千多家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的商水網(wǎng)站制作公司
實例步驟
1.創(chuàng)建一個簡單的 View based application
2.選擇項目文件,然后選擇目標(biāo),然后添加MapKit.framework.
3.添加 Corelocation.framework
4.向 ViewController.xib 添加地圖查看和創(chuàng)建 ibOutlet 并且命名為mapView。
5.通過"File-> New -> File... -> "選擇 Objective C class創(chuàng)建一個新的文件,單擊下一步
6."sub class of"為 NSObject,類作命名為MapAnnotation
7.選擇創(chuàng)建
8.更新MapAnnotation.h ,如下所示
#import#import @interface MapAnnotation : NSObject @property (nonatomic, strong) NSString *title; @property (nonatomic, readwrite) CLLocationCoordinate2D coordinate; - (id)initWithTitle:(NSString *)title andCoordinate: (CLLocationCoordinate2D)coordinate2d; @end
9.更新MapAnnotation.m ,如下所示
#import "MapAnnotation.h"
@implementation MapAnnotation
-(id)initWithTitle:(NSString *)title andCoordinate:
(CLLocationCoordinate2D)coordinate2d{
self.title = title;
self.coordinate =coordinate2d;
return self;
}
@end
10.更新ViewController.h ,如下所示
#import#import #import @interface ViewController : UIViewController { MKMapView *mapView; } @end
11.更新ViewController.m ,如下所示
#import "ViewController.h"
#import "MapAnnotation.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
mapView = [[MKMapView alloc]initWithFrame:
CGRectMake(10, 100, 300, 300)];
mapView.delegate = self;
mapView.centerCoordinate = CLLocationCoordinate2DMake(37.32, -122.03);
mapView.mapType = MKMapTypeHybrid;
CLLocationCoordinate2D location;
location.latitude = (double) 37.332768;
location.longitude = (double) -122.030039;
// Add the annotation to our map view
MapAnnotation *newAnnotation = [[MapAnnotation alloc]
initWithTitle:@"Apple Head quaters" andCoordinate:location];
[mapView addAnnotation:newAnnotation];
CLLocationCoordinate2D location2;
location2.latitude = (double) 37.35239;
location2.longitude = (double) -122.025919;
MapAnnotation *newAnnotation2 = [[MapAnnotation alloc]
initWithTitle:@"Test annotation" andCoordinate:location2];
[mapView addAnnotation:newAnnotation2];
[self.view addSubview:mapView];
}
// When a map annotation point is added, zoom to it (1500 range)
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance
([mp coordinate], 1500, 1500);
[mv setRegion:region animated:YES];
[mv selectAnnotation:mp animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
輸出
運行應(yīng)用程序時,輸出結(jié)果如下
當(dāng)我們向上滾動地圖時,輸出結(jié)果如下
網(wǎng)站標(biāo)題:創(chuàng)新互聯(lián)IOS教程:iOS地圖開發(fā)
瀏覽路徑:http://www.fisionsoft.com.cn/article/cdososp.html


咨詢
建站咨詢
