我想显示我当前位置和所需位置之间的路线。我能够做到这一点,但是当源点和目标点到目前为止,它不会显示路线并给出内存警告。你能建议任何示例代码或任何方法吗?
			
			5754 次
		
1 回答
            3        
        
		
以下代码用于当前位置到所需位置之间的绘制路径
- (void)viewDidLoad {
    [super viewDidLoad];
    mapView = [[[MapView alloc] initWithFrame:
                         CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)] autorelease];
    [self.view addSubview:mapView];
    [self performSelector:@selector(LoadMaps) withObject:self afterDelay:1.0];
}
-(void)LoadMaps{
    MapWithRoutesAppDelegate *app = (MapWithRoutesAppDelegate *)[[UIApplication sharedApplication]delegate];
    CLLocation *location = app.userlocation;
    // Configure the new event with information from the location
    CLLocationCoordinate2D coordinate = [location coordinate];
    NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
    NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
    NSLog(@"dLatitude : %@", latitude);
    NSLog(@"dLongitude : %@",longitude);
    Place* home = [[[Place alloc] init] autorelease];
    home.name = @"Home";
    home.description = @"Sweet home";
    home.latitude = coordinate.latitude;
    home.longitude = coordinate.longitude;
    Place* office = [[[Place alloc] init] autorelease];
    office.name = @"Office";
    office.description = @"Bad office";
    office.latitude = 23.329404;
    office.longitude = 72.0039299;
    [mapView showRouteFrom:home to:office];
    NSLog(@"latitide:%.7f, longitude: %.7f ", coordinate.latitude, coordinate.longitude);
}
在 Appdelegate 方法中包含
#pragma mark- CLLocationManager delegate
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation{
    MapWithRoutesAppDelegate *app = (MapWithRoutesAppDelegate*)[[UIApplication sharedApplication] delegate];
    app.userlocation = newLocation;
    NSLog(@"latitide:%.7f, longitude: %.7f ", app.userlocation.coordinate.latitude, app.userlocation.coordinate.longitude);
}
愿这有很大帮助。
于 2012-11-21T09:17:28.450   回答