如何在 iOS 上的变量中获取位置(纬度和经度值)?

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Resume game cocos2d(恢复游戏 cocos2d)
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)
How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)