How to get Location (latitude amp; longitude value) in variable on iOS?(如何在 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 上使用过位置,但在 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 上的变量中获取位置(纬度和经度值)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS 上的变量中获取位置(纬度和经度值)


基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01