- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我创建了一个只有一个 View 的测试应用程序,该 View 包含一个 MKMapView 和一个充当 MapView 委托(delegate)的 Controller 。
当我进行全新构建(在重新安装之前完全从设备中删除)并记录回调时,我可以看到在用户指示他们是否希望之前调用了两次 mapView:didUpdateUserLocation
显示或不显示他们的当前位置。
传递给回调的 MKUserLocation 对象无效:
2012-03-13 08:20:17.518 MapTest[3325:707] Did update user location: 0.000000,0.000000
2012-03-13 08:20:17.581 MapTest[3325:707] Did update user location: 0.000000,0.000000
这是 MKMapKit 的预期行为还是错误?
我在我的 iPhone 4 上运行它,而不是模拟器。这是 Controller 代码:
#import "ViewController.h"
@implementation ViewController
@synthesize mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.showsUserLocation = YES;
self.mapView.delegate = self;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
-(IBAction)trackButtonTapped:(id)sender
{
self.mapView.showsUserLocation = !self.mapView.showsUserLocation;
}
#pragma mark - MKMapKitDelegate
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
NSLog(@"Did update user location: %f,%f", userLocation.coordinate.latitude, userLocation.coordinate.longitude);
}
-(void)mapViewWillStartLoadingMap:(MKMapView *)mapView
{
NSLog(@"Will start loading map");
}
-(void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
NSLog(@"Did finish loading map");
}
-(void)mapViewWillStartLocatingUser:(MKMapView *)mapView
{
NSLog(@"Will start locating user");
}
-(void)mapViewDidStopLocatingUser:(MKMapView *)mapView
{
NSLog(@"Did stop locating user");
}
-(void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error
{
NSLog(@"Did fail loading map");
}
-(void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error
{
if (error.code == kCLErrorDenied){
NSLog(@"User refused location services");
} else {
NSLog(@"Did fail to locate user with error: %@", error.description);
}
}
@end
最佳答案
我认为这是一个错误。
当用户甚至没有授予权限时, map View 怎么会说用户位置已更新?
我使用的解决方法是检查 userLocation.location
是否为 nil
:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
if (userLocation.location == nil)
return;
//do something with userLocation...
}
关于ios - 这是 MKMapKitDelegate mapView :didUpdateUserLocation? 的错误吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9680576/
我有一个带有 map 的应用程序,并且希望在更新时缩放到当前位置。 我使用 -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKU
我有一个 mapViewController(在导航 Controller 中)。当我第一次打开它时,在 viewDidLoad 之后,- (void)mapView:(MKMapView *)map
当从我的主视图 Controller 按下 View map 按钮时,我正在加载一个 mapviewcontroller: - (IBAction)mapButton:(id)sender {
我无法调用 MKMapView委托(delegate)方法 didUpdateUserLocation . 到目前为止我做了什么: 添加框架 MapKit.framwork在项目中 在 View Co
我正在尝试使用 MapBox 响应用户在 iOS 应用程序中的位置变化,但未调用 didUpdateUserLocation。为什么不调用 didUpdateUserLocation? ViewCon
我正在使用 Storyboard和 Google map 构建一个 iOS 应用程序。使用 iOS6 - Apple map 有一个方法 -(void)mapView:(MKMapView*)mapV
我在使用 MapKit 制作的应用程序方面需要一些帮助 我正在为 didUpdateUserLocation 苦苦挣扎:- 它总是随机地使应用程序崩溃。当我注释掉所有代码时,它可以完美运行,但这不是合
自从我更新到iOS SDK 8和8.1后,出现了很多问题,包括不再调用CLLocationManager的didUpdateLocations方法。 这里是代码: 在 viewDidLoad 中: l
我创建了一个只有一个 View 的测试应用程序,该 View 包含一个 MKMapView 和一个充当 MapView 委托(delegate)的 Controller 。 当我进行全新构建(在重新安
我从 CLLocationManager 和 MKMapView 获取用户的位置。我应该使用哪一个来设置 map 的中心坐标? 此外,模拟器中的两种方法的答案也不同。 CLLocationManage
我有一个 MKMapView,它应该使用自定义 View (不是蓝点)跟踪用户的位置。为了用这个 View 代替蓝点,我这样返回: - (MKAnnotationView *)mapView:(MKM
我正在尝试围绕用户位置 MKMapView 提供 5 个注释...我在我的 didupdateuserlocation 方法中为注释选择随机值...当我运行我的项目时,所有 5 个注释都显示在同一位置
MKMapViewDelegate mapView:didUpdateUserLocation: 方法在 5.0 模拟器上运行时不会被调用,即使在设备设置中给出了所有位置权限也是如此。 对于 4.3,
当我启动我的应用程序时,它会显示一个带有用户位置的 mapView,但 mapView 不会立即显示 UserLocation,打印一些错误,大约 3 分钟后,它会调用“didUpdateUserLo
我是一名优秀的程序员,十分优秀!