gpt4 book ai didi

ios - 如何将当前位置坐标放入 google maps api(相机)

转载 作者:行者123 更新时间:2023-11-29 10:42:37 24 4
gpt4 key购买 nike

我在我的应用程序中使用 google map api,我希望在运行我的代码时自动显示我的位置。我编写并运行了我的代码,但我的代码无法正常工作,我知道我的定位方法不会将我的坐标位置保存在两个变量中。为什么???

请指导我。

    @implementation ViewController
{
double latitudes;
double longitudes;
CLLocationManager *locationManager;
GMSMapView *mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[self GetMyLocation];

// Create a GMSCameraPosition that tells the map to display the

//my friend I don't know why my two variable (latitudes,longitudes)
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitudes longitude:longitudes zoom:14];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
[mapView_ setMapType:kGMSTypeNormal];
}
- (void) GetMyLocation{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
longitudes = currentLocation.coordinate.longitude;
latitudes = currentLocation.coordinate.latitude;
}
}
@end

最佳答案

 @implementation ViewController
{
double latitudes;
double longitudes;
CLLocationManager *locationManager;
GMSMapView *mapView_;
}

- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[self GetMyLocation];

// Create a GMSCameraPosition that tells the map to display the

//my friend I don't know why my two variable (latitudes,longitudes)
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:0 longitude:0 zoom:14];
mapView_ = [GMSMapView mapWithFrame:self.view.frame camera:camera];
mapView_.myLocationEnabled = YES;
[mapView_ setMapType:kGMSTypeNormal];
[self.view addSubView:mapView_];
}

- (void) GetMyLocation{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
longitudes = currentLocation.coordinate.longitude;
latitudes = currentLocation.coordinate.latitude;
}

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:currentLocation.coordinate.longitude longitude:currentLocation.coordinate.latitude zoom:14];

[mapView_ animateToCameraPosition:camera];
}

@end

关于ios - 如何将当前位置坐标放入 google maps api(相机),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23780681/

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