Ios 打开应用程序时获取当前位置
您好,在我的应用程序中,我必须显示从当前位置到目的地位置的路线图。为此,我使用Ios 打开应用程序时获取当前位置,ios,google-maps,core-location,google-maps-sdk-ios,currentlocation,Ios,Google Maps,Core Location,Google Maps Sdk Ios,Currentlocation,您好,在我的应用程序中,我必须显示从当前位置到目的地位置的路线图。为此,我使用googlemapURL来显示路线图,一切正常。但问题是,当它第一次安装应用程序时,它得到的是现金,而不是当前位置 当我最小化应用程序时,它会显示如下警告消息 "appname" would like to use Your current Location 单击“确定”后,我已关闭应用程序并再次打开它,现在它将显示路线图 我的密码 -(void)currentlocation{ locationManag
googlemap
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];
}
我已经使用了上面的代码,我想当用户打开应用程序时,它必须显示警报,一旦用户单击“确定”,它就会显示路线图,请告诉我如何实现我在这里被困了很长时间,请帮助我
谢谢。试试这个
- (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];
}