//第一步:創(chuàng)建標(biāo)注Annotation類,實(shí)現(xiàn)MKAnnotation協(xié)議
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到臺(tái)安網(wǎng)站設(shè)計(jì)與臺(tái)安網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站制作、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋臺(tái)安地區(qū)。#import "ViewController.h"
#import "AnnotationModel.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
manager = [[CLLocationManager alloc] init];
[manager requestAlwaysAuthorization];
MKMapView *mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
mapView.delegate = self;
//設(shè)置地圖類型
mapView.mapType = MKMapTypeStandard;
//設(shè)置當(dāng)前用戶的位置
mapView.showsUserLocation = YES;
//設(shè)置經(jīng)緯度
CLLocationCoordinate2D center = {39.9145402256,116.1767592387};
//設(shè)置精確度,數(shù)值越大,顯示的范圍越大
MKCoordinateSpan span = {0.1,0.1};
//創(chuàng)建一個(gè)區(qū)域
MKCoordinateRegion region = {center,span};
//設(shè)置顯示的區(qū)域
[mapView setRegion:region animated:YES];
[self.view addSubview:mapView];
//第二步:創(chuàng)建標(biāo)注Annotation對(duì)象
CLLocationCoordinate2D coord1 = {39.9117669028,116.1933922217};
AnnotationModel *model1 = [[AnnotationModel alloc] initWithCoordinate:coord1];
model1.title = @"石景山公園";
model1.subtitle = @"北京石景山公園";
CLLocationCoordinate2D coord2 = {39.9261543081,116.1776545774};
AnnotationModel *model2 = [[AnnotationModel alloc] initWithCoordinate:coord2];
model2.title = @"蘋果園";
model2.subtitle = @"石景山區(qū)蘋果園";
CLLocationCoordinate2D coord3 = {39.8637359235,116.2854074940};
AnnotationModel *model3 = [[AnnotationModel alloc] initWithCoordinate:coord3];
model3.title = @"豐臺(tái)公園";
model3.subtitle = @"豐臺(tái)區(qū)豐臺(tái)公園";
CLLocationCoordinate2D coord4 = {39.9128821069,116.3971393161};
AnnotationModel *model4 = [[AnnotationModel alloc] initWithCoordinate:coord4];
model4.title = @"故宮博物館";
model4.subtitle = @"北京市故宮博物館";
//第三步:將Annotation對(duì)象添加到MapView中
[mapView addAnnotation:model1];
[mapView addAnnotation:model2];
[mapView addAnnotation:model3];
[mapView addAnnotation:model4];
}
#pragma mark -MKMapViewDelegate
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
NSLog(@"userLocation:%@",userLocation);
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
NSLog(@"view is %@",view);
}
//第四步:最后實(shí)現(xiàn)MKMapViewDelegate協(xié)議方法,在該代理中創(chuàng)建MKPinAnnotationView標(biāo)注視圖
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id
{
NSLog(@"annotation:%@",annotation);
//自己的位置也是一個(gè)標(biāo)注視圖,它是一個(gè)屬于MKUserLocation這么一個(gè)類
if ([annotation isKindOfClass:[MKUserLocation class]]) {
//如果滿足條件,說(shuō)明當(dāng)前用戶自己的位置,不需要我們?cè)O(shè)置標(biāo)注視圖
return nil;
}
static NSString *identifier = @"annotationView";
//MKPinAnnotationView是一個(gè)大頭針視圖
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:identifier];
//設(shè)置大頭針的顏色
annotationView.pinColor = MKPinAnnotationColorPurple;
//設(shè)置顯示從天而降的動(dòng)畫
annotationView.animatesDrop = YES;
//是否顯示標(biāo)題視圖
annotationView.canShowCallout = YES;
//設(shè)置輔助視圖
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
//防止復(fù)用
annotationView.annotation = annotation;
return annotationView;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。