Map1

1.导入地图的库:Mapkit.framework

2.在导入到工程.m中 导入对应的系统文件   如:

<MapKit/MapKit.h>

MKMapView *mapView = [[MKMapView alloc]initWithFrame:self.view.bounds];

    mapView.delegate = self;

    //地图样式

    mapView.mapType = MKMapTypeHybrid;

//    //缩放

//    mapView.zoomEnabled = NO;

//    //滑动

//    mapView.scrollEnabled = NO;

    //显示当前位置,位置发生变化时候会显示当前位置

    mapView.showsUserLocation = YES;

[self.view addSubview:mapView];


//标注 (大头针)

   微笑 自定义类

    //添加的标注得自定义,同时实现<#(id<MKAnnotation>)#>协议

    MyAnnotation *ann = [[MyAnnotation alloc]init];

    ann.coordinate = CLLocationCoordinate2DMake(37.192279, -122.015586);

    ann.title@"精英";

    ann.subtitle = @"河北四期";

    

    [mapView addAnnotation:ann];

    

    //覆盖物

    这里要能显示效果需要调用渲染器-----在MKMapViewDelegate 的代理方法理写


    CLLocationCoordinate2D points[4];//个数

    points[0] = CLLocationCoordinate2DMake(37.192279, -122.015586);

    points[1] = CLLocationCoordinate2DMake(30.192279, -122.015586);

    points[2] = CLLocationCoordinate2DMake(30.192279, -112.015586);

    points[3] = CLLocationCoordinate2DMake(37.192279, -112.015586);

    // 闭合曲线


//    MKPolygon *gon = [MKPolygon polygonWithCoordinates:points count:4];

//    [mapView addOverlay:gon];

    

    //折线

    MKPolyline *line = [MKPolyline polylineWithCoordinates:points count:4];

    [mapView addOverlay:line];

    

    //圈圈

    MKCircle *circle = [MKCircle circleWithCenterCoordinate:points[3] radius:100000];

    [mapView addOverlay:circle];


//

}

大笑//给覆盖物渲染颜色  ------------------代理方法

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay {

    

    //判断是哪个类

    

    if ([overlay isKindOfClass:[MKPolygon class]]) {

        MKPolygonRenderer *render = [[MKPolygonRenderer alloc]initWithPolygon:overlay];

// 画笔颜色

        render.strokeColor = [UIColor redColor];

        //填充色

        

        render.fillColor = [UIColor greenColor];

        //线的宽度

        render.lineWidth = 3;

        

        return render;

        

    }else if ([overlay isKindOfClass:[MKPolyline class]]){

        

        MKPolylineRenderer *render = [[MKPolylineRenderer alloc]initWithPolyline:overlay];

        render.strokeColor = [UIColor purpleColor];

        render.lineWidth = 1;

        return  render;

        

    }else{

        MKCircleRenderer *render = [[MKCircleRenderer alloc]initWithOverlay:overlay];

        render.strokeColor = [UIColor magentaColor];

        render.fillColor = [UIColor cyanColor];

        render.lineWidth = 2;

        return render;

    }

    

    return nil;

}






微笑

//  MyAnnotation.h

//  MapTest

//

//  Created by laoyu on 15/12/9.

//  Copyright (c) 2015 zhiyou. All rights reserved.

//


#import <Foundation/Foundation.h>

#import <MapKit/MapKit.h>


//自定义标注,必须实现协议的必选属性

//看到了属性马山想到 set get 方法

@interface MyAnnotation : NSObject<MKAnnotation>



@property (nonatomic) CLLocationCoordinate2D coordinate;

@property (nonatomic, copy) NSString *title;

@property (nonatomic, copy) NSString *subtitle;


@end












  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值