問題描述
我想使用我的應用用戶的位置,更具體地說是緯度和經度值.
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 上使用過位置,但在 Internet 上沒有找到與我的問題相符的內容...
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獲取經緯度.
You can use CoreLocation to get the longitude and latitude.
包含框架:
在導航器中單擊您的項目.
Click your project in navigator.
單擊將二進制文件與庫鏈接"下的加號按鈕
Click the plus button under "link binary with libraries"
將 Corelocation 添加到您的項目中.
Add Corelocation to your project.
導入頭文件:
#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;
這篇關于如何在 iOS 上的變量中獲取位置(緯度和經度值)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!