哪一个最适合ios的离线地图?

时间:2015-04-20 05:48:45

标签: ios

我很困惑在ios中使用离线地图,当时互联网连接在线地图获取,当用户互联网连接关闭时,离线地图使用,因此使用了一张地图

请建议你的答案..

1 个答案:

答案 0 :(得分:1)

您可以使用Apple的Reachability课程切换地图,请参阅下文

-(void)setupMapBox{

    RMMapBoxSource *onlineSource = nil;

    Reachability *internet=[Reachability reachabilityWithHostName:@"google.com"];

    if([internet isReachable]){
        //Go for online
        onlineSource = [[RMMapBoxSource alloc] initWithMapID:kMapID];
    }else{
        //If network is not reachable check for offline data if available

        if([[NSUserDefaults standardUserDefaults] objectForKey:@"TileJson"]){
            onlineSource=[[RMMapBoxSource alloc] initWithTileJSON:[[NSUserDefaults standardUserDefaults] objectForKey:@"TileJson"]];
        }else{
            //If nothing is available show an alert.
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"No Network!" message:@"Please check your network!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
        }

    }

    if(onlineSource){
        //If resource is avaiable online/offline load the map else NO.

        [[NSUserDefaults standardUserDefaults] setObject:onlineSource.tileJSON forKey:@"TileJson"];
        [[NSUserDefaults standardUserDefaults] synchronize];


        rmMapView = [[RMMapView alloc] initWithFrame:self.viewMapContainer.frame andTilesource:onlineSource];

        rmMapView.delegate = self;

        //rmMapView.minZoom = 10;

        rmMapView.zoom = 8; // Set the minimum zoom level



        //Point to London
        CLLocationCoordinate2D coordinate;
        coordinate.latitude=51.5072;
        coordinate.longitude=0.1275;

        rmMapView.centerCoordinate=coordinate;

        [self.viewMapContainer addSubview:rmMapView];


        [self addAnnotations];



    }