2014-10-31 62 views

回答

2

對於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