如何使用RubyMotion获取IOS设备的坐标?
答
对于iOS 8,请执行下列操作:
-
这些行添加到您的Rake文件:
app.frameworks += ['CoreLocation'] app.info_plist['NSLocationWhenInUseUsageDescription'] = 'I need it' app.info_plist['NSLocationAlwaysUsageDescription'] = 'I always need it'
-
在
viewDidLoad
在ViewController
加:@locationManager = CLLocationManager.alloc.init @locationManager.requestWhenInUseAuthorization @locationManager.delegate = self @locationManager.startUpdatingLocation
-
实施
locationManager:didUpdateLocations:
def locationManager(manager, didUpdateLocations:locations) coordinate = locations[0].coordinate puts "lat #{coordinate.latitude}, long #{coordinate.longitude}" end
-
如果你只需要在当前位置一次,然后拨打:
manager.stopUpdatingLocation
在
didUpdateLocations
获取位置后。
很好,非常感谢您的帮助 – MikeW 2014-10-31 23:49:42