首页 > ios 百度地图加大头针失败

ios 百度地图加大头针失败

这样添加大头针 失败
在viewdidload里面调用这个方法了!

-(void)addAnnotation{
    CLLocationCoordinate2D locations=CLLocationCoordinate2DMake(coord.latitude, coord.longitude);
    BMKPointAnnotation *annotation=[[BMKPointAnnotation alloc]init];
    annotation.title=@"HELLO";
    annotation.coordinate= locations;
    [LocationMap addAnnotation:annotation];
}

请问是什么原因????


最好把上下文代码也发上来。还有碰到的具体问题。否则别人不理解你的问题是什么。


未在viewDidLoad方法中调用,在自定义手势中调用成功。

- (void)addCustomGestures {
    UILongPressGestureRecognizer *lpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

    lpress.minimumPressDuration = 0.3;
    lpress.allowableMovement = 10.0;

    [_mapView addGestureRecognizer:lpress];
}

在长按手势中点击地图打印经纬度并在此处放置大头针

- (void)longPress:(UIGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
        CGPoint touchPoint = [gestureRecognizer locationInView:_mapView];
        CLLocationCoordinate2D touchMapCoordinate = [_mapView convertPoint:touchPoint toCoordinateFromView:_mapView];

        BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc] init];
        annotation.coordinate = touchMapCoordinate;
        [_mapView addAnnotation:annotation];

        NSLog(@"经度:%f,纬度:%f",touchMapCoordinate.longitude,touchMapCoordinate.latitude);
    }
}

直接在百度官方SDK Demo基础上添加修改,最终效果图:

【热门文章】
【热门文章】