gpt4 book ai didi

ios - 打开应用程序时获取当前位置

转载 作者:行者123 更新时间:2023-11-29 10:41:44 25 4
gpt4 key购买 nike

您好,在我的应用程序中,我必须显示从我当前位置到目的地位置的路线图。为此,我使用 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];

}

我已经使用了上面的代码,当用户打开应用程序时,它必须显示警报,一旦用户单击“确定”,它就会显示路线图,请告诉我如何实现,我一直被困在这里时间请帮帮我。

谢谢。

最佳答案

试试这个 pa..

- (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];
}

关于ios - 打开应用程序时获取当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24256557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com