iOS - 用GPS坐标检测一个地方 [英] iOS - Detect a place with GPS coordinates

查看:115
本文介绍了iOS - 用GPS坐标检测一个地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以用GPS坐标来检测一个地方? (尽可能没有地图)例如检查经度和纬度是否等于或接近这些:

  44 35'25 n 104 42'55w 

44.5903 -104.7153

然后一个警报弹出并显示一条消息!
谢谢。

解决方案

您可以使用以下方式测量硬编码位置与当前用户位置之间的距离:

  CLLocation * hardcoded_location = [[CLLocation alloc] initWithLatitude:latitude1 longitude:longitude1]; 
CLLocation * new_location = newLocation;

CLLocationDistance distance = [hardcoded_location distanceFromLocation:new_location];

然后你可以这样做:

  if(distance  {
[[[UIAlertView alloc] initWithTitle:@Titlemessage:@Messagedelegate:nil cancelButtonTitle:@OK otherButtonTitles:nil,nil] show];

请参阅 https://developer.apple.com/library/mac/documentation/CoreLocation/Reference/CoreLocationDataTypesRef/Reference/reference。 html 以获取更多信息。



更新:
$ b

typedef double CLLocationDistance



距离现有位置的距离测量值(以米为单位)。

is there any way to detect a place with GPS coordinates ? (as much as possible without map ) for example check if longitude and latitude is equal or near to these :

44 35′25″n 104 42′55″w
or
44.5903 -104.7153

then an alert pops up and display a message ! Thanks .

解决方案

You can measure the distance between your "hardcoded" location and current users location with following:

CLLocation *hardcoded_location = [[CLLocation alloc] initWithLatitude:latitude1 longitude:longitude1];
CLLocation *new_location = newLocation;

CLLocationDistance distance = [hardcoded_location distanceFromLocation:new_location];

Then you could do:

if (distance < some_value)
{
    [[[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
}

See https://developer.apple.com/library/mac/documentation/CoreLocation/Reference/CoreLocationDataTypesRef/Reference/reference.html for more info.

UPDATE:

typedef double CLLocationDistance:

A distance measurement (in meters) from an existing location.

这篇关于iOS - 用GPS坐标检测一个地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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