iOS使用Google Map Api创建地图-显示标注-轨迹回放

来源:互联网 发布:用什么看网络电视好 编辑:程序博客网 时间:2024/04/26 23:21

.h    IBOutlet GMSMapView *_mapView;

注: _mapView我这里使用了Storyboard,放地图放在View里面

 

 就是以下三部分。

- (void)initMapView

{

    //创建地图

    [_mapView clear];

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-6.13631

                                                            longitude:106.789352

                                                                 zoom:ZOOM_LEVEL];

    _mapView.mapType = kGMSTypeNormal;

    _mapView.camera = camera;

    _mapView.delegate = self;

    _geocoder = [[GMSGeocoder alloc] init];

 

    polyline = [[GMSPolyline alloc] init];

    linepath = [GMSMutablePath path];


  CLLocationCoordinate2D coords;

            coords.latitude = -6.136271;

            coords.longitude = 106.789216;

             

 

   _mapView.camera = [GMSCameraPosition cameraWithTarget:coords

                                                             zoom:ZOOM_LEVEL];

      

     //显示标注

        GMSReverseGeocodeCallback handler = ^(GMSReverseGeocodeResponse *response,

                                              NSError *error) {

            if (response && response.firstResult) {

                 

                GMSMarker *marker = [[GMSMarker alloc] init];

                marker.position = coords;

                marker.title = response.firstResult.addressLine1;

                marker.snippet = response.firstResult.addressLine2;

                _addressData = response.firstResult.addressLine2;

                [self refreshGpsInfo];

                marker.appearAnimation = kGMSMarkerAnimationNone;

                marker.icon = SETIMAGE(@"deviceannotation.png");

                marker.map = _mapView;

            } else {

                NSLog(@"Could not reverse geocode point (%f,%f): %@",

                      coords.latitude, coords.longitude, error);

            }

        };

         

        [_geocoder reverseGeocodeCoordinate:coords

                          completionHandler:handler];

 

 

//画线,轨迹回放

                [linepath removeAllCoordinates];

                [self drawLineWithLocationArray:trackArray];

 

 

 

 

 

 

 

//画线,使用轨迹回放

- (void)drawLineWithLocationArray:(NSArray *)locationArray

{

     

    if(current_type == _CURRENT_TRACK)

        polyline.strokeColor = [UIColor blueColor];

    else

        polyline.strokeColor = [UIColor redColor];

    polyline.strokeWidth = 6.f;

     

    // for(int idx = 0; idx < pointStrings.count; idx++)

    for(int idx = 0; idx < locationArray.count; idx++)

    {

        CLLocation *location = [locationArray objectAtIndex:idx];

        CLLocationDegrees latitude  = location.coordinate.latitude;

        CLLocationDegrees longitude = location.coordinate.longitude;

         

        // create our coordinate and add it to the correct spot in the array

        CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);

        [linepath addCoordinate:coordinate];

    }

    polyline.path = linepath;

    polyline.map = _mapView;

}

0 0
原创粉丝点击