3

Route-Me アプリに次のものを追加しようとしています。

  • 開始位置にマーカーを追加する
  • マップをユーザーの場所に移動します
  • マーカーをその新しい位置に移動します

私のマップはオフラインの mbtiles ストアからのものであるため、MapBox ios の例の基本的な例を使用しています。

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

#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

マーカー.png がリソース フォルダーに追加されました。

だから私の質問

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

非常に多くのコード スニペットとチュートリアルを試しましたが、どれも機能しませんでした。

4

2 に答える 2

0

Regarding your second question, from the apple docs:

In Xcode 4.0 and 4.1, you could simulate only the current location in your application. As of Xcode 4.2, you can simulate locations other than your current location in iOS applications that use Core Location. To set a location, choose Edit Scheme from the scheme selector in the toolbar, select the Run action, and click the Options tab. You can then choose a location from the Location menu

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

于 2012-04-05T14:07:12.167 に答える
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;
于 2013-08-08T08:31:52.903 に答える