ios - 未检索到纬度和经度
<p><p>iOS9 更新:我是 iOS 新手,正在尝试使用 CoreLocation 来返回纬度和经度值。以下代码从不执行日志输出</p>
<pre><code> -(void)viewWillAppear:(BOOL)animated{
manager = [init];
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
;
}
</code></pre>
<p>这是我的 didUpdateToLocation 函数,但从未达到</p>
<pre><code>- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations{
NSLog(@"Location: %@", locations);
CLLocation *currentLocation = locations.lastObject;
if (currentLocation != nil) {
float latitude = currentLocation.coordinate.latitude;
float longitude = currentLocation.coordinate.longitude;
NSLog(@"dLongitude : %f", longitude);
NSLog(@"dLatitude : %f", latitude);
}
else{ NSLog(@"ERROR");
}
</code></pre>
<p>}</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><code>CLLocationManager</code>是异步的,你应该在委托(delegate)方法中获取经纬度。</p>
<p><code>
locationManager.delegate = self;
</code></p>
<p>然后实现这个委托(delegate)方法:</p>
<p><code>- locationManager:didUpdateLocations:</code></p></p>
<p style="font-size: 20px;">关于ios - 未检索到纬度和经度,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/34192331/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/34192331/
</a>
</p>
页:
[1]