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

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

问题描述:

只是寻找提取GPS坐标的最简单的例子 - 不想在地图上渲染它们或任何东西。如何使用RubyMotion获取IOS设备的坐标?

感谢,

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

  1. 这些行添加到您的Rake文件:

    app.frameworks += ['CoreLocation'] 
    app.info_plist['NSLocationWhenInUseUsageDescription'] = 'I need it' 
    app.info_plist['NSLocationAlwaysUsageDescription'] = 'I always need it' 
    
  2. viewDidLoadViewController加:

    @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获取位置后。

+0

很好,非常感谢您的帮助 – MikeW 2014-10-31 23:49:42