[英]iOS Route-Me: Add User Location Marker
I have been trying to add the following things to a Route-Me app.我一直在尝试将以下内容添加到 Route-Me 应用程序中。
I am using the basic example from MapBox ios example, as my maps are from an offline mbtiles store.我正在使用 MapBox ios 示例中的基本示例,因为我的地图来自离线 mbtiles 商店。
This is my header file:这是我的 header 文件:
#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
And this is my implementation file:这是我的实现文件:
#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
The marker.png has been added to my resources folder. marker.png 已添加到我的资源文件夹中。
So my questions所以我的问题
Any help would be great as I have tried so many code snippets and tutorials but none have ended up working.任何帮助都会很棒,因为我已经尝试了很多代码片段和教程,但都没有成功。
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.在 Xcode 4.0 和 4.1 中,您只能在应用程序中模拟当前位置。 As of Xcode 4.2, you can simulate locations other than your current location in iOS applications that use Core Location.从 Xcode 4.2 开始,您可以在使用 Core Location 的 iOS 应用程序中模拟当前位置以外的位置。 To set a location, choose Edit Scheme from the scheme selector in the toolbar, select the Run action, and click the Options tab.要设置位置,请从工具栏的方案选择器中选择编辑方案,select 运行操作,然后单击选项选项卡。 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 http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_4_2.html
I was able to get it working after cleaning marker after move.移动后清洁标记后,我能够让它工作。
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.