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 上的变量中获取位置(纬度和经度值)


基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01