1

MapView でユーザーの位置を表示する方法を教えてください。オンラインで見つけられる可能性のあることはすべて実行しましたが、まだ機能しません。

viewController で locationUpdate を呼び出す CLLocationManager が AppDelegate にあります。

この(void)locationUpdate:(CLLocation *)locationメソッドは毎回呼び出されlocation、静止画でログに記録すると座標が正しいためNSLog().、iPhone の画面に「青い点」は表示されません。地域も設定されていません。

見て、私が何か欠けているかどうか教えてください。

これは私のヘッダーファイルです:

//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

これは私の実装ファイルの一部です:

//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

お時間をいただきありがとうございます!それは大歓迎です!

4

1 に答える 1

3

Interface Builder のマップ キットでは、[ユーザーの場所を検索] をオンにする必要があります!!

于 2012-07-09T03:25:48.727 に答える