問題描述
我想使用我的應(yīng)用用戶的位置,更具體地說是緯度和經(jīng)度值.
I would like to use the location of my app user, more specifically the latitude and longitude value.
我需要它們?cè)谧兞恐惺褂茫@樣我就可以用 url 發(fā)送它們...
I need them to use in a variable, so that I can send them with an url...
我以前從未在 iOS 和 Xcode 上使用過位置,但在 Internet 上沒有找到與我的問題相符的內(nèi)容...
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 from Germany
推薦答案
可以使用CoreLocation獲取經(jīng)緯度.
You can use CoreLocation to get the longitude and latitude.
包含框架:
在導(dǎo)航器中單擊您的項(xiàng)目.
Click your project in navigator.
單擊將二進(jìn)制文件與庫鏈接"下的加號(hào)按鈕
Click the plus button under "link binary with libraries"
將 Corelocation 添加到您的項(xiàng)目中.
Add Corelocation to your project.
導(dǎo)入頭文件:
#import <CoreLocation/CoreLocation.h>
聲明 CLLocationManager:
CLLocationManager *locationManager;
初始化 locationManager:
- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
}
然后,使用
float latitude = locationManager.location.coordinate.latitude;
float longitude = locationManager.location.coordinate.longitude;
這篇關(guān)于如何在 iOS 上的變量中獲取位置(緯度和經(jīng)度值)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!