iOS百度地图(非Android),点击地图,获取点击位置的坐标并添加上标注

2025-03-12 01:01:53
推荐回答(3个)
回答1:

/**

*点中底图空白处会回调此接口

*@param mapview 地图View

*@param coordinate 空白处坐标点的经纬度

*/

- (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate

{

NSLog(@"onClickedMapBlank-latitude==%f,longitude==%f",coordinate.latitude,coordinate.longitude);

NSString* showmeg = [NSString stringWithFormat:@"您点击了地图空白处(blank click).\r\n当前经度:%f,当前纬度:%f,\r\nZoomLevel=%d;RotateAngle=%d;OverlookAngle=%d", coordinate.longitude,coordinate.latitude,

(int)_mapView.zoomLevel,_mapView.rotation,_mapView.overlooking];

_showMsgLabel.text = showmeg;

}

这段代码是能获取空白处的坐标。

然后获取坐标后

//添加标注

- (void)addPointAnnotation

{

pointAnnotation = [[BMKPointAnnotation alloc]init];

CLLocationCoordinate2D coor(使用上面获取的);

coor.latitude = 上面获取的;

coor.longitude = 上面获取的;

pointAnnotation.coordinate = coor;

pointAnnotation.title = @"test";

pointAnnotation.subtitle = @"此Annotation可拖拽!";

[_mapView addAnnotation:pointAnnotation];

[pointAnnotation release];

}

这段代码是实现添加标注的(有几个委托方法是对标注进行操作的,你可以在里面进行相应操作)

回答2:

Lz,你好!
你实现BMKMapViewDelegate这个协议
里面有很多委托方法
/**

*点中底图空白处会回调此接口

*@param mapview 地图View

*@param coordinate 空白处坐标点的经纬度

*/

- (void)mapView:(BMKMapView *)mapView onClickedMapBlank:(CLLocationCoordinate2D)coordinate

{

NSLog(@"onClickedMapBlank-latitude==%f,longitude==%f",coordinate.latitude,coordinate.longitude);

NSString* showmeg = [NSString stringWithFormat:@"您点击了地图空白处(blank click).\r\n当前经度:%f,当前纬度:%f,\r\nZoomLevel=%d;RotateAngle=%d;OverlookAngle=%d", coordinate.longitude,coordinate.latitude,

(int)_mapView.zoomLevel,_mapView.rotation,_mapView.overlooking];

_showMsgLabel.text = showmeg;

}
这段代码是能获取空白处的坐标。
然后获取坐标后
//添加标注

- (void)addPointAnnotation

{

pointAnnotation = [[BMKPointAnnotation alloc]init];

CLLocationCoordinate2D coor(使用上面获取的);

coor.latitude = 上面获取的;

coor.longitude = 上面获取的;

pointAnnotation.coordinate = coor;

pointAnnotation.title = @"test";

pointAnnotation.subtitle = @"此Annotation可拖拽!";

[_mapView addAnnotation:pointAnnotation];

[pointAnnotation release];

}
这段代码是实现添加标注的(有几个委托方法是对标注进行操作的,你可以在里面进行相应操作)
其实看下官方DEMO里面都有。
希望你能早日解决

回答3:

您好,该问题不属于标注认领问题,给您带来了不便,非常抱歉。