ios - MKMapKit不显示userLocation

标签 ios mapkit cllocationmanager userlocation

我需要在MapView上显示用户位置的帮助。我已尽我所能在网上找到所有内容,但仍然无法正常工作。

我的AppDelegate中有一个CLLocationManager,它在viewController中调用locationUpdate。

每次都调用(void)locationUpdate:(CLLocation *)location方法,并且使用location登录时NSLog().坐标正确,但iPhone屏幕上没有“蓝点”。区域也未设置。

请看看并告诉我是否有任何遗漏。

这是我的头文件:

//My .h file
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKAnnotation.h>
#import <MapKit/MKReverseGeocoder.h>
@interface FirstViewController : UIViewController <MKMapViewDelegate>
{
    MKMapView *mapView;
}
-(void)locationUpdate:(CLLocation *)location;
-(void)locationError:(NSError *)error;
@end

这是我的实现文件的一部分:
//My .m file
#import "FirstViewController.h"
@implementation FirstViewController
- (void)viewDidLoad
{
    mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
    mapView.showsUserLocation = YES;
    mapView.mapType = MKMapTypeStandard;
    mapView.delegate = self;

    CLLocationCoordinate2D location;
    MKCoordinateRegion region;// = {{0.0,0.0},{0.0,0.0}};
    location.latitude = -33.8771;
    location.longitude = 18.6155;
    MKCoordinateSpan span;
    span.latitudeDelta = 0.01;
    span.longitudeDelta = 0.01;
    region.span = span;
    region.center = location;
    [mapView setRegion:region animated:TRUE];
    [mapView regionThatFits:region];
    [super viewDidLoad];
}
-(void)locationUpdate:(CLLocation *)location
{
    CLLocationCoordinate2D loc = [location coordinate];
    [mapView setCenterCoordinate:loc];
    if([mapView showsUserLocation] == NO)
    [mapView setShowsUserLocation:YES];
    NSLog(@"User Loc: %f, %f", mapView.userLocation.location.coordinate.latitude,
                     mapView.userLocation.location.coordinate.longitude);
    NSLog(@"In MapView: %@",[location description]);
}
@end

感谢您的时间!
非常感谢!

最佳答案

您在Interface Builder中的 map 工具包需要选中(查找用户位置)!

关于ios - MKMapKit不显示userLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6020612/

相关文章:

ios - 如何交换 tableviewcell 中的 UIImage

ios - 使用 MKAnnotation 的自动属性合成警告

iOS CLLocationManager 在一个单独的类中

iOS:应用程序挂起状态下的位置更新

ios - 类消息的接收者类型 "WkAlertAction"是前向声明

ios - 如何以编程方式检查 ios 设备当前的 userInterfaceStyle?

iphone - iPhone 的 MapKit 框架中使用图像代替默认图钉?

ios - 无法使用 setPitchEnabled 将其值更改为 YES

ios - 使用 CLLocationManager 检测何时达到最佳定位精度

ios - 如何使用 swift 将相同的背景图像添加到我的 ios 应用程序中的所有 View ?