Xcode 地图显示位置区域,但不显示位置点

Xcode map showing area of location, but not point of location

我正在尝试让我的应用程序在地图上显示不同的位置。当我点击位置按钮时,它会放大地图上的区域,但不会用蓝点或大头针标记该地点。

这就是我的。

-(IBAction)loc
{ 
  MKCoordinateRegion region= {{0.0,0.0},{0.0,0.0}};
  region.center.latitude=34.245832;
  region.center.longitude=-88.722346;
  region.span.longitudeDelta=0.01f;
  region.span.latitudeDelta=0.01f;
  [mapView setRegion:region animated:YES];
}

我错过了什么?

如果要标记位置,则需要添加注释或叠加层。

MKPointAnnotation and MKPinAnnotationView

阅读 MKMapView (particularly the section on Annotating the Map), and MKMapViewDelegate

的文档

基本上,您需要……

  1. 定义一个符合MKAnnotation
  2. 的对象
  3. 创建该对象的实例并设置其 coordinate
  4. addAnnotation到地图视图
  5. 调用 showAnnotations 将地图缩放到所需的注释
  6. 要显示自定义图钉,请实施 MKMapViewDelegate 方法 mapView(_:viewFor:)