-4
A
回答
13
实施CLLocationManagerDelegate写此功能,在你的viewController的viewDidLoad方法调用它。
-(void)startLocationManager
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
[locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D coordinate = [newLocation coordinate];
double dblLatitude = coordinate.latitude;
double dblLongitude = coordinate.longitude;
}
+1
非常感谢您在iOS 6中使用 –
+0
didUpdateToLocation已弃用,因此请使用** didUpdateLocations ** – swiftBoy
2
您使用CoreLocation框架。 这里你可以得到示例代码http://mobileorchard.com/hello-there-a-corelocation-tutorial/
4
如果您使用CLLocationmanager,请确保您检查是否首先启用位置服务。我想这样做是为了获得当前位置:
if ([CLLocationManager locationServicesEnabled])
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
CLLocationCoordinate2D *currentLocation = locationManager.location;
[locationManager stopUpdatingLocation];
[locationManager release];
}
如果您正在使用的MapView,您可以用获取当前位置:
[mapView setShowsUserLocation:YES];
CLLocationCoordinate2D *currentLocation = mapView.userLocation.coordinate;
相关问题
- 1. 通过GPS/IP获取iPhone的位置
- 2. 获取GPS位置
- 3. 在BlackBerry上获取GPS位置
- 4. Python在macOS上获取GPS位置
- 5. 如何使用AsyncTask获取GPS位置?
- 6. 如何获取GPS或位置
- 7. 如何获取当前的GPS位置?
- 8. 位置GPS iPhone SDK
- 9. iPhone的GPS位置
- 10. 如何在Android(2.2)设备上获取用户的GPS位置
- 11. 如何在单击按钮上获取GPS位置?
- 12. 如何确定GPS位置是否已在android上获取?
- 13. Android-获取GPS位置
- 14. GPS获取错误位置
- 15. 无法获取GPS位置
- 16. 通过GPS位置获取位置
- 17. 获取gps在黑莓的位置
- 18. 在ios8.0中获取GPS的位置App
- 19. 在GPS中获取当前位置?
- 20. 在AsyncTask中获取GPS位置
- 21. 通过GPS获取当前位置在地图上绘制路线? iPhone(iOS6)
- 22. 如何从iPhone/Android获取GPS坐标?
- 23. 如何在iPhone上通过GPS获取“标题”信息WebApp
- 24. 如何在iPhone上可靠地获取位置
- 25. 如何在地图上获取动态位置的方向iphone
- 26. 我可以使用Corona SDK获取Iphone/Android GPS位置吗?
- 27. 如何获得当前位置在iphone上的地图位置
- 28. 如何在C#桌面应用程序中获取GPS位置?
- 29. 如何在react-native-maps中获取GPS位置
- 30. 如何在Android中使用gps获取当前位置?
你应该让即使是最小的尝试询问之前搜索Apple的文档题。这个问题非常普遍。 – jtbandes