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 上的变量中获取位置(纬度和经度值)
基础教程推荐
- 突出显示朗读文本(在 iPhone 的故事书类型应用程序中) 2022-01-01
- 如何将多个组件添加到 PickerView? 2022-01-01
- - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 如何工作 2022-01-01
- 新的@SystemApi 注解是什么意思,和@hide 有什么区别 2022-01-01
- 我的 UIImageView 的任务 2022-01-01
- 可可/目标C(OSX不是iOS)从子对象访问父对象 2022-01-01
- Android:STATE_SELECTED不工作 2022-01-01
- 在 iOS8 中无法获得正确的键盘高度值 2022-01-01
- 在 appComponent dagger 2 中动态添加测试模块? 2022-01-01
- 在 Android 模拟器中激活网络位置提供程序? 2022-01-01
