首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKMapKit没有显示userLocation

MKMapKit没有显示userLocation
EN

Stack Overflow用户
提问于 2011-05-16 16:46:03
回答 1查看 944关注 0票数 1

我需要帮助显示用户的位置在我的MapView。我已经做了我可以在网上找到的一切,但它仍然不起作用。

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

每次调用(void)locationUpdate:(CLLocation *)location方法时,location坐标都是正确的,当仍然使用NSLog().登录时,在我的iPhone屏幕上没有“蓝点”。这个地区也没有被设定好。

请看一看,如果我遗漏了什么,请告诉我。

这是我的头文件:

代码语言:javascript
复制
//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

--这是我实现文件的一部分:

代码语言:javascript
复制
//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

谢谢您抽时间见我!非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-09 03:25:48

界面生成器中的地图工具包需要检查(查找用户位置)!!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6020612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档