Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将当前位置坐标放入谷歌地图api(摄像头)_Ios_Objective C_Google Maps - Fatal编程技术网

Ios 如何将当前位置坐标放入谷歌地图api(摄像头)

Ios 如何将当前位置坐标放入谷歌地图api(摄像头),ios,objective-c,google-maps,Ios,Objective C,Google Maps,我在我的应用程序中使用谷歌地图api,我想在运行代码时在视图中自动显示我的位置。 我编写代码并运行,但我的代码不起作用,我知道我的定位方法不会将坐标位置保存在两个变量中。为什么 请告诉我这件事 @implementation ViewController { double latitudes; double longitudes; CLLocationManager *locationManager; GMSMapV

我在我的应用程序中使用谷歌地图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

您在哪里签入模拟器或设备?为什么它不更新是因为您试图设置新的GMSCameraPosition,而CLLocationManager尚未更新它的位置。当对象找到其当前位置时,将didUpdateLocation方法中的update camera调用作为其当前位置coordinates@Anbu.Karthik我查一下device@ShamsAhmed我的朋友请指导我并告诉我代码…你遇到了什么问题我的朋友此代码不起作用,因为不将mapView添加到视图中我将mapView添加到哪里?将其添加到viewDidLoad或VIEWDIDAPPE dude mapView_uu是GMSMapView类,我没有添加到self.view不起作用,但当我写self.view=mapView_u时,它起作用了!!!但是我想在viewDidLoad方法中使用mapView,当我将它添加到视图中时,我不能在viewDidLoad中使用mapView!!!为什么???对不起,我以前的代码不清楚,这个新的更新应该可以工作。
 @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