有一个应用程序可以成功找到您的GPS位置,但我需要能够将该GPS与GPS位置列表进行比较,如果两者相同,那么您将获得奖励.
我以为我有它工作,但似乎没有.
我有'newLocation'作为你所在的位置,我认为问题是我需要能够分离newLocation的long和lat数据.
到目前为止,我试过这个:
NSString *latitudeVar = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.latitude];
NSString *longitudeVar = [[NSString alloc] initWithFormat:@"%g°", newLocation.coordinate.longitude];
Run Code Online (Sandbox Code Playgroud)
GPS位置列表的示例:
location:(CLLocation*)newLocation;
CLLocationCoordinate2D bonusOne;
bonusOne.latitude = 37.331689;
bonusOne.longitude = -122.030731;
Run Code Online (Sandbox Code Playgroud)
然后
if (latitudeVar == bonusOne.latitude && longitudeVar == bonusOne.longitude) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"infinite loop firday" message:@"infloop" delegate:nil cancelButtonTitle:@"Stinky" otherButtonTitles:nil ];
[alert show];
[alert release];
}
Run Code Online (Sandbox Code Playgroud)
这会产生一个错误'无效操作数到二进制==有strut NSstring和CLlocationDegrees'
有什么想法吗?
我有一个sqlite数据库与长和拉特的商店,我想找到最近的5家商店.
所以下面的代码工作正常.
if(sqlite3_prepare_v2(db, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while (sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *branchStr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
NSNumber *fLat = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 1)];
NSNumber *fLong = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 2)];
NSLog(@"Address %@, Lat = %@, Long = %@", branchStr, fLat, fLong);
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:[fLat floatValue] longitude:[fLong floatValue]];
NSLog(@"Distance i meters: %f", [location1 getDistanceFrom:location2]);
[location1 release];
[location2 release];
}
}
Run Code Online (Sandbox Code Playgroud)
我知道我到每个商店的距离.我的问题是.
将距离放回sqlite行是否更好,当我逐步通过数据库时,我有一行.我怎么做?我是否使用UPDATE语句?有人有一段代码可以帮助我.
我可以将sqlite读入一个数组然后对数组进行排序.您是否建议采用上述方法?这更有效吗?
最后,如果有人有更好的方法来获得最近的5家商店,那就爱听.
我是一名学习Objective-C的新iPhone开发人员,我正在尝试动态计算用户纬度/经度坐标与SQLite表中纬度/经度坐标之间的距离.我知道我们可以使用CLLocations方法:
(CLLocationDistance)distanceFromLocation:(const CLLocation *)location
Run Code Online (Sandbox Code Playgroud)
要做到这一点,但鉴于我拥有的数据,我不确定如何使用它.如何使用上述方法使用成对的纬度/经度坐标,考虑到上述方法只处理CLLocation类型的位置对象?任何人都可以给我一个简单的例子,说明如何使用这对方法使用两对纬度/经度坐标?
如何在后台保持CLLocation更新.我相信您需要在Application委托中注册应用程序以执行此操作,但我无法在任何地方找到对此的引用?
我将CLLocation用于一个在人们跑步或行走时在地图视图中记录其踪迹的应用程序,但我发现当我的设备仍然(不移动)时,-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *位置也经常被呼叫吗?目前,我的位置经理的期望精度为10米,距离过滤器为10。
如何处理这种情况?我尝试使用大的distancefilter值(例如150),但是我发现如果执行此操作,那么我无法准确记录人在跑步或走路的时间
主题说明了一切.为什么我在这2行收到此错误消息?
NSArray *coordinates = [locationDetails[@"coordinates"] componentsSeparatedByString:@","];
CLLocationDegrees *lat = [coordinates[1] doubleValue]; //here is the red arrow <----
Run Code Online (Sandbox Code Playgroud)
并且将显示以下消息:
使用不兼容类型'double'的表达式初始化'CLLocationDegrees*'(又名'double*')
我正在尝试访问didEnterRegion委托中最近的信标的主要值和次要值.但是,将值打印到控制台时,它们返回null
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
if ([region isKindOfClass:[CLBeaconRegion class]]) {
CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
int major = [beaconRegion.major intValue];
int minor = [beaconRegion.minor intValue];
NSLog(@" Major %@ Minor %@", beaconRegion.major, beaconRegion.minor);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在一个ViewController中保存用户的坐标,以便它可以用于创建可以在另一个ViewController中显示的Annotation.
在视图控制器中,我使用代码存储坐标
NSUserDefaults.standardUserDefaults().setObject( Location, forKey: "Location")
Run Code Online (Sandbox Code Playgroud)
在地图视图控制器中显示我正在尝试使用代码获取坐标的注释
let Location = NSUserDefaults.standardUserDefaults().stringForKey("Location")
var Annotation = MKPointAnnotation()
Annotation.coordinate = Location
Run Code Online (Sandbox Code Playgroud)
它告诉我type的值为type String?的值CLLocationCoordinate2D.
那么如何将CLLocationCoordinate2D坐标转换为类型的值String?
我为mapView suing swift写了一个简单的例子,但是我得到了打印 Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
我将mapView添加到viewController并开始定位.我requestWhenInUseAuthorization()之前也打过电话startUpdatingLocation()
我设置了Info.plist
现在我同时设置NSLocationAlwaysUsageDescription和NSLocationWhenInUseUsageDescription,这是行不通的.

Tere是我的代码,出了什么问题?
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var locationManager: CLLocationManager?
var mapView: MKMapView?
override func viewDidLoad() {
super.viewDidLoad()
let locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = 10
locationManager.delegate = self
locationManager.pausesLocationUpdatesAutomatically = true
if CLLocationManager.locationServicesEnabled() {
let status: CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if status == CLAuthorizationStatus.NotDetermined {
if …Run Code Online (Sandbox Code Playgroud) 我有以下代码,其目的是遍历当前Apple地图视图上的所有注释并更新其位置坐标.
for existingMarker in self.mapView.annotations {
existingMarker.coordinate.latitude = 12.12121212
existingMarker.coordinate.longitude = 14.312121121
}
Run Code Online (Sandbox Code Playgroud)
可悲的是,这是不允许的.我被告知'坐标'是一个唯一的属性.所以这显然不是我想要更新MKAnnotation已经在mapView上绘制的注释的位置.那怎么办呢?具体来说,我想这样做并让地图"重绘"新坐标尽快.我确信这一定是可能的,因为它似乎是一个常见的用例.
cllocation ×10
ios ×6
iphone ×4
objective-c ×4
swift ×3
apple-maps ×1
distance ×1
geolocation ×1
ibeacon ×1
ios4 ×1
ios9 ×1
location ×1
mkannotation ×1
mkmapview ×1
nscoding ×1
sdk ×1
sqlite ×1
xcode ×1