资源简介

基于cocos2d-x开发的瓦片地图demo,实现了双指缩放、地图拖拽、双击放大功能

资源截图

代码片段和文件信息

//
//  MapViewController.m
//  Single View Test Project
//
//  Created by Chiuan on 12-12-16.
//  Copyright (c) 2012年 Chiuan. All rights reserved.
//

#import “MapViewController.h“

@interface MapViewController ()

@end

static MapViewController * instance;
@implementation MapViewController

@synthesize myMapView;
@synthesize locationManager;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        instance = self;
    }
    return self;
}

+(MapViewController*)getInstance{
    return instance;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    //when open a mapcheck if the user confirm the location services
    self.locationManager = [[CLLocationManager alloc] init];
    NSLog(@“checking..“);
    if(![CLLocationManager locationServicesEnabled]){
        NSLog(@“location not open.“);
        
    }
    else{
        NSLog(@“checking..OK“);
        [self.locationManager setDelegate:self];
        [self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; //just use default accuracy
        [self.locationManager setDistanceFilter:200];
        [self.locationManager startUpdatingLocation];
    }
    NSLog(@“checking..end“);
    self.myMapView = [[MKMapView alloc] initWithframe:self.view.bounds];
    [self.myMapView setDelegate:self];
    self.myMapView.mapType = MKMapTypeStandard;
    self.myMapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [self.myMapView setScrollEnabled:NO];
    [self.myMapView setZoomEnabled:NO];
    
    self.myMapView.showsUserLocation = TRUE;
    [self.view addSubview:self.myMapView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)dealloc{
    [myMapView release];
    [locationManager release];
    [playerAnnotation release];
    [super dealloc];
}

//show the player region
//this region need to change size by setting!
-(void)showPlayerRegion:(CLLocationDistance)paramRadious{
    CLLocationCoordinate2D center = self.myMapView.userLocation.coordinate;
    //Need to mark the center.
    NSLog(@“center = %f   %f“center.latitudecenter.longitude);
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(center paramRadious paramRadious);
    MKCoordinateRegion newRegion = [self.myMapView regionThatFits:viewRegion];
    [self.myMapView setCenterCoordinate:center animated:YES];
    [self.myMapView setRegion:newRegion animated:YES];
    
    //need to show player icon!
    playerAnnotation = [[PlayerAnnotation alloc] initWithCoordinates:center title:@“Player“ subtitle:@“I‘m chiuan.“ mapView:self.myMapView];
    [self.myMapView addAnnotation:playerAnnotation];
    
    //add control of gesturer
    UILongPressGestureRecognizer *lp

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-02-09 12:49  Cocos2dTest\
     文件        6148  2013-02-09 22:12  Cocos2dTest\.DS_Store
     目录           0  2013-02-09 22:12  __MACOSX\
     目录           0  2013-02-09 22:12  __MACOSX\Cocos2dTest\
     文件          82  2013-02-09 22:12  __MACOSX\Cocos2dTest\._.DS_Store
     目录           0  2013-02-09 22:11  Cocos2dTest\.git\
     文件        6148  2012-12-24 01:23  Cocos2dTest\.git\.DS_Store
     目录           0  2013-02-09 22:12  __MACOSX\Cocos2dTest\.git\
     文件          82  2012-12-24 01:23  __MACOSX\Cocos2dTest\.git\._.DS_Store
     目录           0  2012-12-19 22:34  Cocos2dTest\.git\branches\
     文件          15  2012-12-19 22:34  Cocos2dTest\.git\COMMIT_EDITMSG
     文件         111  2012-12-19 22:34  Cocos2dTest\.git\config
     文件          73  2012-12-19 22:34  Cocos2dTest\.git\description
     文件          23  2012-12-19 22:34  Cocos2dTest\.git\HEAD
     目录           0  2012-12-19 22:34  Cocos2dTest\.git\hooks\
     文件         452  2012-12-19 22:34  Cocos2dTest\.git\hooks\applypatch-msg.sample
     文件         896  2012-12-19 22:34  Cocos2dTest\.git\hooks\commit-msg.sample
     文件         189  2012-12-19 22:34  Cocos2dTest\.git\hooks\post-update.sample
     文件         398  2012-12-19 22:34  Cocos2dTest\.git\hooks\pre-applypatch.sample
     文件        1704  2012-12-19 22:34  Cocos2dTest\.git\hooks\pre-commit.sample
     文件        4951  2012-12-19 22:34  Cocos2dTest\.git\hooks\pre-rebase.sample
     文件        1239  2012-12-19 22:34  Cocos2dTest\.git\hooks\prepare-commit-msg.sample
     文件        3611  2012-12-19 22:34  Cocos2dTest\.git\hooks\update.sample
     文件       52264  2013-02-09 12:49  Cocos2dTest\.git\index
     目录           0  2012-12-19 22:34  Cocos2dTest\.git\info\
     文件          35  2012-12-19 22:34  Cocos2dTest\.git\info\exclude
     目录           0  2013-02-09 22:12  __MACOSX\Cocos2dTest\.git\info\
     文件         171  2012-12-19 22:34  __MACOSX\Cocos2dTest\.git\info\._exclude
     目录           0  2012-12-19 22:34  Cocos2dTest\.git\logs\
     文件         163  2012-12-19 22:34  Cocos2dTest\.git\logs\HEAD
     目录           0  2012-12-19 22:34  Cocos2dTest\.git\logs\refs\
............此处省略1675个文件信息

评论

共有 条评论