showsUserLocation在iPhone 4.0中不显示蓝点 [英] showsUserLocation does not display blue dot in iPhone 4.0

查看:499
本文介绍了showsUserLocation在iPhone 4.0中不显示蓝点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我创建了一个CLLocationManager,称它开始更新,将mapView.showsUserLocation设置为YES,并返回nil为userLocation注释。
下面是我的UIMapViewController中代码的一些片段:

   - (void)viewDidLoad 
{
CLLocationManager * locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation]; (CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D userCoordinate =(CLLocation * locationManager.location.coordinate;
[map setCenterCoordinate:userCoordinate animated:YES];
[map setShowsUserLocation:YES];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id< MKAnnotation>)annotation
{

MKAnnotationView * mapIconView =(MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@mapIconView];

//不要乱用用户位置注释
if(annotation == mapView.userLocation)
return nil;

//等
}

直截了当。一切工作正常 - 地图缩放到我的位置,因为它应该,我已经确认所有的方法都按预期调用 - 但没有蓝点。无论我在哪里或多少次,我都不能得到蓝色的点。

  mapView.setUserLocation =是; 

我在这里缺少什么?

解决方案

它是mapView.showUserLocation = YES;



你似乎使用了错误的语句'set'而不是' / p>

和FYI,你不必为了获得用户位置而与位置管理器混淆。当您设置 mapview.showUserLoction = YES 并加载地图时,Corelocation会自动触发。



希望它有帮助:)


So, I've created a CLLocationManager, called it to start updating, set mapView.showsUserLocation to YES, and returned nil for the userLocation annotation. Here are some snippets from my code in my UIMapViewController:

- (void)viewDidLoad
{
     CLLocationManager *locationManager = [[CLLocationManager alloc] init];
     [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{ 
 CLLocationCoordinate2D userCoordinate = locationManager.location.coordinate;
 [map setCenterCoordinate:userCoordinate animated:YES];
 [map setShowsUserLocation:YES];  
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

 MKAnnotationView *mapIconView = (MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:@"mapIconView"];

 // Don't mess with the user location annotation
     if (annotation == mapView.userLocation)
              return nil;

    // etc.
}     

This all seems pretty straightforward. Everything works fine--the map zooms to my location as it should, and I've confirmed that all the methods are called as expected--but no blue dot. Can't get the blue dot for the life of me, no matter where or how many times I say

mapView.setUserLocation = YES;

What am I missing here?

解决方案

It's mapView.showUserLocation = YES;

You seem to have used the wrong statement 'set' instead of 'show'.

And FYI, you don't have to mess with the location manager just to get the userlocation. Corelocation automatically gets fired when you set mapview.showUserLoction = YES and load the map.

Hope it helps :)

这篇关于showsUserLocation在iPhone 4.0中不显示蓝点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆