如何在 iOS 上的变量中获取位置(纬度和经度值)? [英] How to get Location (latitude & longitude value) in variable on iOS?

查看:16
本文介绍了如何在 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 上的变量中获取位置(纬度和经度值)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆