简体   繁体   English

MKMapView位置不会更新

[英]MKMapView location won't update

After posting on Apple's iOS Devs forums with no answer, I'm trying to see if anyone's got any experience with such issue. 在苹果公司的iOS Devs论坛上发布无任何答案后,我试图查看是否有人对此问题有任何经验。 I'm using xcode for iOS 7. 我将xcode用于iOS 7。

MapView won't update. MapView不会更新。 I'm quite sure the problem's within the simulator, though I'm not sure how to check it. 我很确定问题出在模拟器中,尽管我不确定如何检查。 I'd love to take this project on a real device but my iOS 7 device's still in store. 我很想在一个真实的设备上进行这个项目,但是我的iOS 7设备仍在存储中。

I created a MKMapView nested under a View (nested under a ViewController) -> Added CoreLocation and MapKit into Frameworks -> Connected the MKMapView to the right property mapView. 我创建了一个嵌套在View下的MKMapView(嵌套在ViewController下)->将CoreLocation和MapKit添加到框架中->将MKMapView连接到正确的属性mapView。

My files look like this: 我的文件如下所示:

MapScanViewController.h: MapScanViewController.h:

#import <UIKit/UIKit.h>    
#import <MapKit/MapKit.h>

@interface MapScanViewController : UIViewController<MKMapViewDelegate>

// I was trying to create a label and print the 
// userLocation description into the label - but none worked
@property (nonatomic,retain) IBOutlet UILabel *myLabel;

@property (nonatomic,strong) IBOutlet MKMapView *mapView;

@end

And MapScanViewController.m : MapScanViewController.m

#import "MapScanViewController.h"

@implementation MapScanViewController

- (void)viewDidLoad    
{
    [super viewDidLoad];
    _mapView.delegate = self;
}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);

    [_mapView setRegion:[_mapView regionThatFits:region] animated:YES];

    // Label idea did not work eiter
    [_myLabel setText:[userLocation description]];    
}

@end

When I try to change location to Apple's Infinite loop, the map stays still like nothing's changing at all. 当我尝试将位置更改为Apple的无限循环时,地图仍然保持不变,就像什么都没有改变一样。 Also tried to use bicycle ride and running but nothing happened. 还尝试使用自行车骑行和跑步,但没有任何反应。 I tried to reset the iOS Simulator few times which did not help at all and of course tried to manually set the location from within xcode it-self. 我尝试过几次重置iOS模拟器,这根本没有帮助,当然,我尝试从xcode自身中手动设置位置。

Tried to add/force this (which did not help either): 试图添加/强制执行此操作(这也没有帮助):

if (_mapView.showsUserLocation)
{
_mapView.showsUserLocation = NO;
_mapView.showsUserLocation = YES;
}

None worked for me. 没有人为我工作。 MapView just wont respond. MapView不会响应。


I verified the map view 我验证了地图视图

// Meters-Miles convertion
#define METERS_PER_MILE 1609.344

// Just wanted to check if MapView's dead or not - worked- it took me to see (39.28..., -76.58...)
- (void)viewWillAppear:(BOOL)animated {
    // 1
    CLLocationCoordinate2D zoomLocation;
    zoomLocation.latitude = 39.281516;
    zoomLocation.longitude= -76.580806;

    // 2
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);

    // 3
    [_mapView setRegion:viewRegion animated:YES];
}

you have to call _mapView.showsUserLocation = YES; 您必须调用_mapView.showsUserLocation = YES; before you get anything from the map. 在您从地图上获取任何东西之前。

That call will for prompt the user for access to location services. 该呼叫将提示用户访问位置服务。

As Daij-Djan said Try like this 正如Daij-Djan所说的尝试这样

- (void)viewDidLoad    
{
 _mapView.showsUserLocation = YES;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM