2012-04-05 9 views
3

私はRoute-Meアプリに次のものを追加しようとしています。iOS Route-Me:ユーザー位置マーカーを追加

  • は、
  • は、その新しい場所

私はMapBoxのIOSの例から基本的な例を使用していますにマーカを移動し

  • ユーザーの場所
  • にマップを移動開始位置にマーカーを追加します。私のマップはオフラインのmbtilesストアからのものです。

    #import <UIKit/UIKit.h> 
    
    #import "RMMapView.h" 
    #import "RMMarker.h" 
    #import "RMMapViewDelegate.h" 
    #import "RMMarkerManager.h" 
    #import "CoreLocation/CoreLocation.h" 
    
    @interface MBTiles_ExampleViewController : UIViewController 
    { 
        RMMapView *mapView; 
    } 
    
    @property (nonatomic, retain) IBOutlet RMMapView *mapView; 
    @property (nonatomic, retain) CLLocationManager *locationManager; 
    @property (nonatomic, retain) CLLocation *currentLocation; 
    @property (nonatomic, retain) RMMarkerManager *markerManager; 
    @property (nonatomic, retain) RMMarker *locationMarker; 
    
    @end 
    

    そして、これが私の実装ファイルです:

    これは私のヘッダファイルである

    #define kStartingLat 30.0f 
    #define kStartingLon -10.0f 
    #define kStartingZoom 1.5f 
    
    #import "MBTiles_ExampleViewController.h" 
    
    #import "RMMBTilesTileSource.h" 
    #import "RMMapContents.h" 
    #import "RMMarker.h" 
    
    #import "RMMarkerManager.h" 
    #import "CoreLocation/CoreLocation.h" 
    
    
    @implementation MBTiles_ExampleViewController 
    
    @synthesize mapView; 
    @synthesize currentLocation; 
    @synthesize locationManager; 
    @synthesize markerManager; 
    @synthesize locationMarker; 
    
    
    
    (void)viewDidLoad 
    { 
        CLLocationCoordinate2D startingPoint; 
    
        startingPoint.latitude = kStartingLat; 
        startingPoint.longitude = kStartingLon; 
    
        NSURL *tilesURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"control-room-0.2.0" ofType:@"mbtiles"]]; 
    
        RMMBTilesTileSource *source = [[[RMMBTilesTileSource alloc] initWithTileSetURL:tilesURL] autorelease]; 
    
        [[[RMMapContents alloc] initWithView:self.mapView 
               tilesource:source 
              centerLatLon:startingPoint 
               zoomLevel:kStartingZoom 
              maxZoomLevel:[source maxZoom] 
              minZoomLevel:[source minZoom] 
             backgroundImage:nil] autorelease]; 
    
        mapView.enableRotate = NO; 
        mapView.deceleration = NO; 
    
        mapView.backgroundColor = [UIColor blackColor]; 
    
        mapView.contents.zoom = kStartingZoom; 
    
        if (nil == locationManager) 
         locationManager = [[CLLocationManager alloc] init]; 
        locationManager.delegate = self; 
    
        locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    
        [locationManager startUpdatingLocation]; 
    
    
        UIImage *iconImage = [UIImage imageNamed:@"marker.png"]; 
    
        locationMarker = [[RMMarker alloc] initWithUIImage: iconImage]; 
    
    
    
        [markerManager addMarker: locationMarker AtLatLong: startingPoint]; 
    
    } 
    
    (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
    { 
        [mapView moveToLatLong:newLocation.coordinate]; 
    
        RMLatLong newCoords = {newLocation.coordinate.latitude, newLocation.coordinate.longitude}; 
    
        if (nil != markerManager) 
         [markerManager moveMarker:locationMarker AtLatLon: newCoords]; 
    
    } 
    
    (void)dealloc 
    { 
        [mapView release]; 
    
        [super dealloc]; 
    } 
    
    @end 
    

    marker.pngは、私のリソースフォルダに追加されました。

    だから私の質問

    1. なぜ開始マーカーが表示されていませんか?
    2. 私はSnowLeopardでxcodeを使用していますので、シミュレータは実際に私の場所を見つけることができますか?地図は動かないので。

    私は非常に多くのコードスニペットとチュートリアルを試してみましたが、どれもうまくいきませんでした。アップルのドキュメントから2番目の質問については

    +0

    NSLog(@ "Text goes here")をいくつか追加します。コード全体でデバッグ出力を出力する行。表示しようとしている場所、画像が無し、画像のサイズ、コードが呼び出されているかどうかなどを確認したい場合があります。 –

    答えて

    0

    、:Xcodeの4.0と4.1では

    は、あなたがあなたのアプリケーションで唯一の現在位置をシミュレートすることができます。 Xcode 4.2以降、Core Locationを使用するiOSアプリケーションでは、現在地以外の場所をシミュレートできます。場所を設定するには、ツールバーのスキーマセレクタから「Edit Scheme」を選択し、「Run」アクションを選択して、「Options」タブをクリックします。あなたは、私はそれが移動後のマーカーを清掃した後に動作させることができた場所メニュー

    http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_4_2.html

    +0

    xcode 4.2は将来の道ですが、別の解決策がありますか? – tjmgis

    0

    から場所を選択することができます。

    marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"marker.png"] anchorPoint:CGPointMake(0.5f, 1.f)]; 
    [mapView.contents.markerManager addMarker:marker AtLatLong:locPoland]; 
    [mapView.contents.markerManager moveMarker:marker AtLatLon:locWawa]; 
    [mapView.markerManager moveMarker:marker AtLatLon: locUser]; 
    [mapView moveToLatLong:locUser]; 
    marker = nil; 
    
    関連する問題