Pinpointing the location of a Device

Problem

You want to find the latitude and longitude of a device.

Solution

Use the CLLocationManager class:

#import "WSYViewController.h"

#import <MapKit/MapKit.h>

@interface WSYViewController
()<CLLocationManagerDelegate>

@property (nonatomic,strong)CLLocationManager *
myLocationManager;

@end

@implementation WSYViewController

-(void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations

{

//we received the new loaction

NSLog(@"Latitude = %f ",[[locations
lastObject] coordinate].latitude);

NSLog(@"longitude = %f ",[[locations
lastObject] coordinate].longitude);

}

-(void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error

{

NSLog(@"Failed to receive user‘s location
");

}

- (void)viewDidLoad

{

[super viewDidLoad];

if ([CLLocationManager
locationServicesEnabled]) {

self.myLocationManager = [[CLLocationManager alloc]init];

self.myLocationManager.delegate = self;

[self.myLocationManager startUpdatingLocation];

}else

{

//location services
are not enabled

//take appropriate
action for instance prompt the user to enable the location services

NSLog(@"Location
services are not enabled");

}

}

@end

In this code, myLocationManager is a property of type
CLLocationManager. The current class is also the delegate of the location
manager in this sample code.

时间: 2024-10-31 09:28:56

Pinpointing the location of a Device的相关文章

PatentTips - Device virtualization and assignment of interconnect devices

BACKGROUND Standard computer interconnects, particularly for personal computers or workstations, may employ a bus such as Peripheral Component Interconnect ("PCI"), Industry Standard Architecture ("ISA"), or Extended ISA ("EISA&qu

著名ERP厂商的SSO单点登录解决方案介绍一

      SSO英文全称Single Sign On,单点登录.SSO是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统.它包括可以将这次主要的登录映射到其他应用中用于同一个用户的登录的机制.认证系统的主要功能是将用户的登录信息和用户信息库相比较,对用户进行登录认证:认证成功后,认证系统应该生成统一的认证标志(ticket),返还给用户.它是比较流行的企业业务整合的解决方案之一.       企业应用集成(EAI, Enterprise Application Integr

appium python api收集

1.contexts contexts(self): Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的控件 :Usage: driver.contexts 用法 driver.contexts 2. current_context current_context(self): Returns the current context of the current session. 返回当前会话的当前上

Resource Access Based on Multiple Credentials

A collection of multiple?user?credentials?each associated with one of multiple different users is obtained at a device, and one or more of the multiple?user credentials?are verified. A determination is made as to whether access to a resource is permi

Method for browsing internet of things and apparatus using the same

A method for browsing Internet of things (IoT) and an apparatus using the same are provided. In the method for browsing IoT, when a mobile device executes a browser, the browser receives information on IoT devices and displays the IoT devices on a ma

Windows 10 IoT Serials 5 - 如何为树莓派应用程序添加语音识别与交互功能

都说语音是人机交互的重要手段,虽然个人觉得在大庭广众之下,对着手机发号施令会显得有些尴尬.但是在资源受限的物联网应用场景下(无法外接鼠标键盘显示器),如果能够通过语音来控制设备,与设备进行交互,那还是很实用的.继上一篇<Windows 10 IoT Serials 4 - 如何在树莓派上使用Cortana语音助手>之后,本文将详细讲述如何为运行Windows 10 IoT Core系统的树莓派添加语音识别和语音交互功能. 1. 硬件准备 树莓派2/树莓派3.5V/2A电源.TF卡(8GB以上)

TelephonyManager类使用方法大全

这个类是很有用地,可以得到很多关于手机的信息,做应用时必须的工具. 不废话,直接上注释后的代码,请享用: <code> /** * *@author dingran *创建日期 2010-4-29 下午05:02:47 * */ package net.sunniwell.app; import android.app.Activity; import android.os.Bundle; import android.telephony.CellLocation; import androi

Appium===Appium+Python API(转)

Appium+python自动化8-Appium Python API 前言: Appium Python API全集,不知道哪个大神整理的,这里贴出来分享给大家. 1.contexts contexts(self): Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的控件 :Usage: driver.contexts 用法 driver.contexts 2. current_context cu

appium python api(转)

Appium_Python_Api文档 1.contextscontexts(self): Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的控件 :Usage: driver.contexts 用法 driver.contexts 2. current_contextcurrent_context(self): Returns the current context of the current s