您好,在我的应用程序中,我必须将路线图从当前位置显示到目的地位置。为此,我使用google map
URL来显示路线图,一切正常。但问题是当第一次安装应用程序获取现金而不是获取当前位置时。
当我最小化应用程序时,它显示警告消息,如。
"appname" would like to use Your current Location
单击确定后,我已关闭应用程序并再次打开它,显示路线图。
我的代码。
-(void)currentlocation{
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[self->locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
mapView = [[[MapView alloc] initWithFrame:
CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)] autorelease];
[self.view addSubview:mapView];
Place* home = [[[Place alloc] init] autorelease];
home.name = @"Home";
home.description = @"Sweet home";
home.latitude = 13.0051850;
home.longitude = 77.62698590;
Place* office = [[[Place alloc] init] autorelease];
office.name = @"Office";
office.description = @"Bad office";
office.latitude = coordinate.latitude;
office.longitude = coordinate.longitude;
[mapView showRouteFrom:home to:office];
}
我已经使用了上面的代码,我希望当用户打开应用程序时,它必须显示警报,一旦用户单击确定它有显示路线图请告诉我如何实现我已经被困在这里很长时间时间请帮帮我。
感谢。
答案 0 :(得分:2)
试试这个......
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
Place* home = [[[Place alloc] init] autorelease];
home.name = @"Home";
home.description = @"Sweet home";
home.latitude = 13.0051850;
home.longitude = 77.62698590;
Place* office = [[[Place alloc] init] autorelease];
office.name = @"Office";
office.description = @"Bad office";
office.latitude = currentLocation.coordinate.latitude;
office.longitude = currentLocation.coordinate.longitude;
[mapView showRouteFrom:home to:office];
}
// Stop Location Manager
[locationManager stopUpdatingLocation];
}