我目前在我的項目中使用Google Maps API。我正在設置默認的攝像頭/縮放到用戶的位置。我這樣做:Google Maps API:獲取當前位置的座標iOS
@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 location]; CLLocationCoordinate2D coordinate = [位置座標]; –
谷歌地圖有一個功能,獲取用戶的位置,但我不知道如何得到它 – Alexyuiop
請參閱:http:// stackoverflow。問題/ 16331767 /如何獲取當前位置在谷歌地圖 - sdk在iphone中 希望它有幫助 –