【问题标题】:Can we turn on/off the GPS programmatically in iPhone?我们可以在 iPhone 中以编程方式打开/关闭 GPS 吗?
【发布时间】:2011-08-09 06:47:43
【问题描述】:

我想知道我们可以在 iPhone 中以编程方式打开/关闭 GPS 吗?

【问题讨论】:

    标签: iphone objective-c ios ipad gps


    【解决方案1】:

    一个简单的例子:

    //Init location manager 
    
    CLLocationManager* locationManager = [ [ CLLocationManager alloc] init];
    locationManager.delegate = self; //we must implement the protocol
    
    //Choose your accuracy level
    
    //To turn on gps (if it isn't on already)
    [locationManager startUpdatingLocation];
    
    //To turn gps off (if no other apps are listening)
    [locationManager stopUpdatingLocation];
    

    还有更多,您可以或多或少地监控准确性,甚至可以使用 wifi/手机信号塔。请先阅读示例以获得最佳用法。

    【讨论】:

      【解决方案2】:

      在 iOS 5 之前,从第三方应用程序启动手机设置的行为并不一致,但在 iOS5 中,这一点得到了改进。

      如果我们调用startUpdatingLoaction方法如下代码,如果定位服务关闭,系统警报会弹出,如果我们点击设置按钮,它将导航到手机设置。

      CLLocationManager *locationManager = [[CLLocationManager alloc] init];
      locationManager.delegate = self;
      [locationManager startUpdatingLocation];
      

      【讨论】:

        【解决方案3】:

        如果您使用CLLocationManager,GPS 将会打开。

        位置管理器将首先通过三角测量获取位置,然后转动 GPS 以获得更精确的定位。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-05-27
          • 1970-01-01
          • 1970-01-01
          • 2012-09-01
          • 2013-08-18
          • 1970-01-01
          相关资源
          最近更新 更多