简体   繁体   English

是否可以通过使用iOS中的Mapbox SDK在离线状态下找到用户当前位置

[英]Is it possible to find user current location in offline by using mapbox SDK in ios

i am working on offline map. 我正在离线地图上工作。 i am using mapbox sdk. 我正在使用Mapbox SDK。
But i am not able to track user current location. 但是我无法跟踪用户的当前位置。
I wrote code like below : 我写了code like below :

  (void)viewDidLoad {

    [super viewDidLoad];
    RMMBTilesSource *offlineSource = [[RMMBTilesSource alloc] initWithTileSetResource:@"control-room-0.2.0" ofType:@"mbtiles"];

    RMMapView *mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:offlineSource];
    mapView.zoom = 2;
    [self.view addSubview:mapView];


    mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

    mapView.adjustTilesForRetinaDisplay = YES; // these tiles aren't designed specifically for retina, so make them legible

    [mapView setUserTrackingMode:RMUserTrackingModeFollow animated:true];
    mapView.draggingEnabled = YES;
    mapView.showsUserLocation = YES;
    mapView.userInteractionEnabled = YES;

    [self.view addSubview:mapView];
}

Thanks in advance. 提前致谢。 please help me on this 请帮助我

Actually you can do it, but you have to turn on your wifi and 3g. 实际上您可以做到,但是您必须打开wifi和3g网络。 But if showsUserLocation doesn't work for you you can do it using CLLocationManager. 但是,如果showsUserLocation不适合您,则可以使用CLLocationManager进行操作。 Hope my code can help you. 希望我的代码可以为您提供帮助。

- (IBAction)findMe:(id)sender {
    if (!_trackingActive) {
        NSLog(@"Tracking mode activated");
        _locationManager = [[CLLocationManager alloc] init];
        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        _locationManager.delegate = self;
        [_locationManager startUpdatingLocation];
        _startLocation = nil;
        _trackingActive = true;
        self.mapView.showsUserLocation = YES;

        if ([UIView instancesRespondToSelector:@selector(setTintColor:)])
            self.mapView.tintColor = [UIColor colorWithRed:0.200 green:1.000 blue:0.200 alpha:1];

        self.mapView.userLocation.title = @"Hola";
        self.mapView.userLocation.badgeIcon = [UIImage imageNamed:@"info"];
        self.mapView.userLocation.annotationIcon = [UIImage imageNamed:@"info"];

    }else{
        NSLog(@"Tracking mode deactivated");
        [_locationManager stopUpdatingLocation];
        _trackingActive = false;
        self.mapView.showsUserLocation = NO;
    }
}

-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
          fromLocation:(CLLocation *)oldLocation
{
    NSString *currentLatitude = [[NSString alloc]
                                 initWithFormat:@"%+.6f",
                                 newLocation.coordinate.latitude];
    _latitude.text = currentLatitude;

    NSString *currentLongitude = [[NSString alloc]
                                  initWithFormat:@"%+.6f",
                                  newLocation.coordinate.longitude];
    _longitude.text = currentLongitude;

    NSString *currentHorizontalAccuracy =
    [[NSString alloc]
     initWithFormat:@"%+.6f",
     newLocation.horizontalAccuracy];
    _horizontalAccuracy.text = currentHorizontalAccuracy;

    NSString *currentAltitude = [[NSString alloc]
                                 initWithFormat:@"%+.6f",
                                 newLocation.altitude];
    _altitude.text = currentAltitude;

    NSString *currentVerticalAccuracy =
    [[NSString alloc]
     initWithFormat:@"%+.6f",
     newLocation.verticalAccuracy];
    _verticalAccuracy.text = currentVerticalAccuracy;

    if (_startLocation == nil)
        _startLocation = newLocation;

    CLLocationDistance distanceBetween = [newLocation
                                          distanceFromLocation:_startLocation];

    NSString *tripString = [[NSString alloc]
                            initWithFormat:@"%f",
                            distanceBetween];
    _distance.text = tripString;
    self.mapView.centerCoordinate = CLLocationCoordinate2DMake(currentLatitude.doubleValue, currentLongitude.doubleValue);
}

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

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