1

我试图弄清楚为什么轨迹栏按钮不会将地图移回用户当前位置。它只是变成等待的旋转轮(下图),地图也不会移动。谢谢。

显示等待图像的轨迹栏按钮

下面是我的部分代码。那里的坐标是针对市中心的,但我已经将模拟器的位置设置到了另一个地方,所以如果我点击轨迹栏按钮,我希望能移到那里。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self focusMap];
    self.mapView.showsUserLocation = YES;
}    
- (void) focusMap 
{
    CLLocationCoordinate2D coord = { -33.882365, 151.211025 };
    MKCoordinateSpan span = {0.005,0.005};
    MKCoordinateRegion region = {coord, span};
    [mapView setRegion: region animated: YES];

    MKUserTrackingBarButtonItem* trackerButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView: self.mapView];
    self.navigationItem.rightBarButtonItem = trackerButton;
    [trackerButton release];

    mapView.zoomEnabled = YES;
}
4

1 回答 1

1

You're in the simulator right? When you are using the simulator you need to simulate the GPS from Xcode by supplying a pre-defined GPX file or make one of your own. Look for a location arrow just above the debug window. Alternatively, within the Simulator you can choose Debug -> Location. To make a custom GPX file it has the following format:

<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode"> 

    <wpt lat="59.90855" lon="10.721554">
         <name>Oslo, Norway</name>
    </wpt>

</gpx>
于 2012-07-07T17:14:01.567 回答