如何使用RubyMotion获取IOS设备的坐标?

时间:2014-10-31 13:04:54

标签: rubymotion

只是寻找提取gps坐标的最简单的例子 - 不想在地图或任何东西上渲染它们。

谢谢,

1 个答案:

答案 0 :(得分:2)

对于iOS 8,请执行以下操作:

  1. 将这些行添加到您的Rakefile:

    app.frameworks += ['CoreLocation']
    app.info_plist['NSLocationWhenInUseUsageDescription'] = 'I need it'
    app.info_plist['NSLocationAlwaysUsageDescription'] = 'I always need it'
    
  2. viewDidLoad中的ViewController添加:

    @locationManager = CLLocationManager.alloc.init
    @locationManager.requestWhenInUseAuthorization
    @locationManager.delegate = self
    @locationManager.startUpdatingLocation
    
  3. 实施locationManager:didUpdateLocations:

    def locationManager(manager, didUpdateLocations:locations)
      coordinate = locations[0].coordinate
      puts "lat #{coordinate.latitude}, long #{coordinate.longitude}"
    end
    
  4. 如果您只需要一次当前位置,请致电:

    manager.stopUpdatingLocation
    
    获取didUpdateLocations中的位置后