gpt4 book ai didi

ios - 谷歌地图 API : Getting coordinates of current location iOS

转载 作者:技术小花猫 更新时间:2023-10-29 11:13:30 25 4
gpt4 key购买 nike

我目前正在我的项目中使用 Google Maps API。我正在尝试将默认相机/缩放设置为用户位置。我这样做:

@implementation ViewController{

GMSMapView *mapView_;

}
@synthesize currentLatitude,currentLongitude;

- (void)viewDidLoad
{
[super viewDidLoad];
mapView_.settings.myLocationButton = YES;
mapView_.myLocationEnabled = YES;


}
- (void)loadView{

CLLocation *myLocation = mapView_.myLocation;

GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(myLocation.coordinate.latitude, myLocation.coordinate.longitude);
marker.title = @"Current Location";
marker.map = mapView_;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:myLocation.coordinate.latitude
longitude:myLocation.coordinate.longitude
zoom:6];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];

self.view = mapView_;
NSLog(@"%f, %f", myLocation.coordinate.latitude, myLocation.coordinate.longitude);

}

但是,它不起作用,因为当我这样做了

NSLog(@"%f, %f", myLocation.coordinate.latitude, myLocation.coordinate.longitude);

返回0, 0,不给出当前位置坐标。如何正确获取用户的坐标?

最佳答案

.h

#import <CoreLocation/CoreLocation.h>
@property(nonatomic,retain) CLLocationManager *locationManager;

.m

- (NSString *)deviceLocation 
{
NSString *theLocation = [NSString stringWithFormat:@"latitude: %f longitude: %f", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude];
return theLocation;
}

- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}

已回答 here .

关于ios - 谷歌地图 API : Getting coordinates of current location iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17057805/

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