嗨,在我的应用程序中,我必须显示从我当前位置到目的地位置的路线图。为此,我使用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];
}
我已经使用了我想要的上面的代码,当用户打开应用程序时它必须显示警报,一旦用户单击确定,它就会显示路线图请告诉我如何实现我已经卡在这里很长时间了请帮助我出去。
谢谢。