问题描述
|
友人
我正在尝试在地图上绘制折线。为此,我使用此代码。工作正常。在这里,我使用Fake_location(CSV文件),但是如果我想使用数据库位置,我的数据库表如下所示:
PK LocationID VARCHAR(20)
_id INTEGER
FK1 journeyID VARCHAR(20)
Altitude FLOAT
Longitude FLOAT
Latitude FLOAT
Speed FLOAT
Accuracy FLOAT
LocationDate DATETIME
LastSyncDate DATETIME
如何使用经度和纬度?
-(id)init {
self = [super init];
Nsstring* filePath = [[NSBundle mainBundle] pathForResource:ROUTE_FILE_NAME ofType:@\"csv\"];
Nsstring *fake_location = [[Nsstring alloc] initWithContentsOfFile:filePath];
pointsArray = [[fake_location componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] retain];
pointsArrayIndex = 0;
oldLocationsIndex = 0;
[fake_location release];
oldLocations = [[NSMutableArray alloc] init];
return self;
}
-(void)startUpdatingLocation {
aTimer = [NSTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL target:self selector:@selector(injectNextLocation) userInfo:nil repeats:YES];
}
-(void)stopUpdatingLocation {
[aTimer invalidate];
}
-(void)injectNextLocation{
if (pointsArray.count == pointsArrayIndex) {
[self stopUpdatingLocation];
return;
}
CLLocation *oldLocation = nil;
if ([oldLocations count] > 0) {
oldLocation = [oldLocations objectAtIndex:oldLocationsIndex];
oldLocationsIndex++;
}
Nsstring *pointString = [pointsArray objectAtIndex:pointsArrayIndex];
NSArray *latLong = [pointString componentsSeparatedByString:@\",\"];
//NSLog(@\"%@\",latLong);
CLLocationCoordinate2D coords;
coords.latitude = [[latLong objectAtIndex:0] doubleValue];
coords.longitude = [[latLong objectAtIndex:1] doubleValue];
float altitude = [self getRandomValue:200 toMax:220];
CLLocation *myLocation = [[CLLocation alloc] initWithCoordinate:coords altitude:altitude horizontalAccuracy:1 verticalAccuracy:1 timestamp:[NSDate date]];
[self.delegate locationManager:self didUpdatetoLocation:myLocation fromLocation:oldLocation];
[oldLocations addobject:myLocation];
[myLocation release];
pointsArrayIndex++;
}
-(void)dealloc {
[pointsArray release];
[aTimer release];
[oldLocations release];
[super dealloc];
}
#pragma mark -
#pragma mark functions
- (float) getRandomValue:(float)min toMax:(float)max {
NSNumber *rand;
rand = [NSNumber numberWithUnsignedInt:arc4random()];
return fmod([rand floatValue],(max-min+1))+min;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)