2016-04-07 79 views
0

我正在获取设备的当前态度和经度并用nslog打印它,但现在如何在地图上更新这些经度和纬度。这里是我的代码,请看看这个。如何使用google map api获取iOS中的当前位置?

- (void)viewDidLoad { 
[super viewDidLoad]; 



GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.868 
                 longitude:151.2086 
                  zoom:12]; 

mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera]; 



mapView_.settings.myLocationButton = YES; 
self.view = mapView_; 
mapView_.settings.compassButton = YES; 

[self startStandardUpdates]; 

    } 



      - (void)startStandardUpdates 
     { 
// Create the location manager if this object does not 
// already have one. 

NSLog(@"startupdatelocation"); 
if (nil == _locationManager) 
    _locationManager = [[CLLocationManager alloc] init]; 

_locationManager.delegate = self; 
_locationManager.desiredAccuracy = kCLLocationAccuracyKilometer; 

// Set a movement threshold for new events. 
_locationManager.distanceFilter = 10; // meters 

[self.locationManager startUpdatingLocation]; 
     } 



     - (void)startSignificantChangeUpdates 
     { 
// Create the location manager if this object does not 
// already have one. 
if (nil == _locationManager) 
    _locationManager = [[CLLocationManager alloc] init]; 

_locationManager.delegate = self; 
[self.locationManager startMonitoringSignificantLocationChanges]; 
     } 

     - (void)locationManager:(CLLocationManager *)manager 
didUpdateLocations:(NSArray *)locations { 
// If it's a relatively recent event, turn off updates to save power. 
CLLocation* location = [locations lastObject]; 
NSLog(@"location %@", location); 
NSDate* eventDate = location.timestamp; 
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; 
if (abs(howRecent) < 15.0) { 
    // If the event is recent, do something with it. 
    NSLog(@"latitude %+.6f, longitude %+.6f\n",location.coordinate.latitude, 
      location.coordinate.longitude); 



     } 
     } 

我正在打印当前的经纬度现在我怎么会在地图上显示该位置也请帮我在这种情况下。

+0

您添加的静止坐标的理由** cameraWithLatitude:-33.868 经度:151.2086 ** –

+0

好吧,先生,但是当我删除这行代码什么都没有出现在视图 –

+0

我已经导入corelocation框架,但它不工作 –

回答

0

当前设备的位置应该从iOS请求 - https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html

比你能表现出与设备位置标记在地图上

+0

的某个部分给我建议我应该在plist中为这个“UIRequiredDeviceCapabilities”添加关键值? –

+0

@sandeeptomar NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription是需要的密钥。阅读更多的例子在这里http://stackoverflow.com/questions/26134641/how-to-get-current-location-lat-long-in-ios-8 –

相关问题