【发布时间】:2013-06-08 02:40:13
【问题描述】:
我目前正在我的项目中使用 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,并且不给出当前位置坐标。如何正确获取用户坐标?
【问题讨论】:
-
这条线在做什么? CLLocation *myLocation = mapView_.myLocation;要获取当前位置,我们需要 1. 添加 CoreLocation 框架 2. 创建 CLLocationManager 的对象 CLLocationManager *locationManager = [[CLLocationManager alloc] init]; 3. [locationManager startUpdatingLocation]; CLLocation *location = [locationManager 位置]; CLLocationCoordinate2D 坐标 = [位置坐标];
-
谷歌地图有获取用户位置的功能,但是不知道怎么获取
-
参考:stackoverflow.com/questions/16331767/…希望对您有所帮助
-
我看了那个,但它似乎不适合我
-
当我使用它时出现空白屏幕,我在自定义视图上显示地图并想要获取当前位置的纬度、经度?
标签: ios objective-c google-maps location google-maps-sdk-ios