2012-04-05 3 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. SnowLeopard에서 xcode를 사용하고있어서 시뮬레이터가 실제로 내 위치를 찾을 수 있습니까? 지도가 움직이지 않기 때문에.

    많은 코드 스 니펫 및 자습서를 시도했지만 아무도 작동하지 않아 도움이 될 수 있으면 도움이 될 것입니다. 사과 문서에서 두 번째 질문에 대해서는

  • +0

    NSLog (@ "Text goes here")를 추가하십시오. 코드를 통해 디버그 출력을 인쇄하는 행. 표시하려는 위치, 이미지가 nil인지, 이미지의 크기인지, 코드가 호출되는지 여부 등을 확인하고자 할 것입니다. –

    답변

    0

    : 엑스 코드 4.0 및 4.1에서

    , 당신은 당신의 응용 프로그램은 현재 위치를 시뮬레이션 할 수 있습니다. Xcode 4.2부터 코어 위치를 사용하는 iOS 어플리케이션에서 현재 위치 이외의 위치를 ​​시뮬레이션 할 수 있습니다. 위치를 설정하려면 도구 막대의 구성표 선택자에서 구성표 편집을 선택하고 실행 동작을 선택한 다음 옵션 탭을 클릭하십시오. 그런 다음 나는 그것을 이동 후 마커를 청소 한 후 작업 얻을 수있었습니다 위치 메뉴

    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;