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

标签 ios objective-c google-maps

我在我的应用程序中使用 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/

相关文章:

iphone - 如何在没有任何服务器的情况下在 2 个以上的设备之间创建连接

ios - 如何了解我是否已经为应用内购买付款

objective-c - 核心数据将保存 : method

c# - 如何从谷歌地图读取返回的xml值

iphone - 如何通过网络链接在 iPhone 上启动 Google map ?

ios-尝试在图像上绘制点,然后通过线连接它们

iphone - UITableViewCell无法正确更新

ios - 从 App 启动 Periscope

objective-c - UIWebView:如何隐藏网页的部分内容?

javascript - 谷歌地图 - 使用自定义 json 样式*和* TERRAIN View