如何获取位置(纬度和经度值)在iOS上的变量? [英] How to get Location (latitude & longitude value) in variable on iOS?
问题描述
我想使用我的应用程式使用者的位置,更准确的说,是纬度和经度值。
I would like to use the location of my app user, more specifically the latitude and longitude value.
我需要他们在一个变量中使用,以便我可以发送一个url ...
I need them to use in a variable, so that I can send them with an url...
我从来没有在iOS和Xcode上的位置工作,发现没有匹配我的问题在互联网上...
I never worked before withe locations on iOS and Xcode and found nothing matching for my problem on the Internet...
所以我希望有人可以解释它给我的代码示例:
So I hope someone can explain it to my with a code sample :)
Thx for u help
来自德国的Laurenz
Thx for u help Laurenz from Germany
推荐答案
您可以使用CoreLocation来获取经度和纬度。
You can use CoreLocation to get the longitude and latitude.
包括框架:
点击导航器中的项目。
点击链接二进制图书馆下的加号按钮
Click the plus button under "link binary with libraries"
向您的项目添加Core位置。
Add Corelocation to your project.
导入头文件:
#import <CoreLocation/CoreLocation.h>
声明CLLocationManager :
CLLocationManager *locationManager;
initialize locationManager:
- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
}
然后使用
$ b
Then, use
float latitude = locationManager.location.coordinate.latitude;
float longitude = locationManager.location.coordinate.longitude;
这篇关于如何获取位置(纬度和经度值)在iOS上的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!