谷歌地图

作者: 缺舟 | 来源:发表于2018-09-04 10:23 被阅读19次
    锦烟霞
    1. 注册应用获取key
    2. 集成SDK
    pod 'GoogleMaps'#地图
    
    1. VC中添加地图视图:GMSMapView
    //谷歌地图
    #import <GoogleMaps/GoogleMaps.h>
    @property (nonatomic,strong) GMSMapView *gmMapView;
    -(GMSMapView *)gmMapView{
        if (_gmMapView == nil) {
            CGFloat latitude = 0.0f;
            CGFloat longitude = 0.0f;
            CLLocation *location = [[CLLocation alloc] initWithLatitude: latitude longitude: longitude];
            /**
             *设置显示区域
             *location.coordinate位置信息
             *zoom精度
             */
            GMSCameraPosition *camera = [GMSCameraPosition cameraWithTarget:location.coordinate zoom:15];
            _gmMapView = [GMSMapView mapWithFrame:CGRectMake(0,0 ,SCREEN_WIDTH,SCREEN_HEIGHT-64) camera:camera];
        }
        return _gmMapView;
    }
    

    注意:在谷歌地图中使用的坐标系区分地域:
    在国外是地球坐标系:WGS84,在国内是火星坐标GCJ-02关于坐标

    1. 添加自定义地标:GMSMarker
            //初始化
            GMSMarker *benginMarker = [[GMSMarker alloc] init];
            //位置
            benginMarker.position = ...;
            //标题
            benginMarker.title = @"";
            //详细
            benginMarker.snippet = @"";
            //图标
            benginMarker.icon = ...;
            //显示
            benginMarker.map = self.gmMapView;
    
    1. 添加轨迹:GMSPolylineGMSMutablePath
        //初始化路线信息
        GMSMutablePath *path = [GMSMutablePath path];
        for (CLLocation *location in self.locations) {
            //添加路线上的点坐标
            [path addCoordinate:location.coordinate];
        }
        //根据路线初始化一条轨迹
        GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
        //轨迹的宽度
        polyline.strokeWidth = 5.0;
        //轨迹颜色
        [polyline setStrokeColor:RGBA(81,191,179,1)];
        //添加轨迹
        polyline.map = self.gmMapView;
    

    相关文章

      网友评论

        本文标题:谷歌地图

        本文链接:https://www.haomeiwen.com/subject/mgawwftx.html