我想显示两个坐标之间的地图。我已使用此代码来显示包含两个坐标的地图矩形。但我的两个坐标都没有显示,而是显示了两个坐标之间的区域(不包括坐标)。我应该怎么做才能包含我的两个坐标?
let coordinate1 = CLLocationCoordinate2DMake(28.53, 77.39)
let coordinate2 = CLLocationCoordinate2DMake(29.13,76.69)
// convert them to MKMapPoint
let p1 = MKMapPointForCoordinate (coordinate2);
let p2 = MKMapPointForCoordinate (coordinate1);
let mapRect = MKMapRectMake(fmin(p1.x,p2.x), fmin(p1.y,p2.y), fabs(p1.x-p2.x), fabs(p1.y-p2.y));
mapView.setVisibleMapRect(mapRect, animated: true)
Run Code Online (Sandbox Code Playgroud) 我收到此错误:
\n\n\n\n\n更新位置时出错操作无法完成\xe2\x80\x99。\n(kCLErrorDomain 错误 0。)
\n
我的问题是,几乎每次运行模拟器时都会显示此错误,并且在模拟器运行的整个过程中它都会一直显示该错误(每次我向 viewController 提供地图时,它都会显示此错误)。最奇怪的是有时会出现此错误错误为零,一切都很好。在实际设备上,它工作正常,但是当我想尝试使用位置(在模拟器上)时,我必须重新启动模拟器大约 7 次,直到它工作为止。
\n\n这是Info.plist:
\n\n\n\n我的位置是自定义的:
\n\n\n\n这是我的代码:
\n\nfunc locationManager(manager: CLLocationManager, didFailWithError error: NSError) {\n print("Error while updating location " + error.localizedDescription)\n\n let alertController = UIAlertController(title: "Sorry!", message: "We were unable to find your location", preferredStyle: UIAlertControllerStyle.Alert)\n let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)\n alertController.addAction(defaultAction)\n\n presentViewController(alertController, animated: true, completion: nil)\n print("Error...")\n }\nRun Code Online (Sandbox Code Playgroud)\n\n我的问题是为什么它只是有时有效?\n谢谢你:)
\n我想解释一下我所面临的情况.默认情况下,iPhone模拟器的当前位置是"循环".我有一个正在南非使用的应用程序(例如).如果我在模拟器上测试"靠近我"的功能.它什么都不会显示.同样如果我想在真实设备上测试我的应用程序,它对我来说不起作用,因为我位于印度.我要做的是"在模拟器上设置当前位置".Blackberry模拟器和Android模拟器/模拟器提供 - 设置当前位置以在模拟器上进行测试.
在这种情况下你怎么做?
我对这项技术很陌生,所以请帮助我.
我正在使用CLLocationManager来获取当前位置,我的应用程序有自定义设置,显示他已经允许当前位置的状态,即我们写时默认出现的消息提示
[self.locationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)
如果用户点击不允许该消息提示并返回到我的应用程序自定义设置并更改关闭按钮以获取位置,我可以获取用户的当前位置.
如何实现这个东西,请帮忙.
提前致谢
我无法获得当前位置.当我在不同的地方启动我的应用程序时,App可以获得最后的位置.但我不想最后的位置.如果您关闭应用并重新启动它,现在应用可以获取当前位置.即使首次启动应用程序,我如何获得当前位置?
- (void)viewDidLoad
{
[super viewDidLoad];
[locationManager startUpdatingLocation];
self.mapView.delegate = self;
[self.mapView setShowsUserLocation:YES];
locationManager.delegate=self;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
locationManager.distanceFilter=kCLDistanceFilterNone;
location = [locationManager location];
CLLocationCoordinate2D coord;
coord.longitude = location.coordinate.longitude;
coord.latitude = location.coordinate.latitude;
lat = coord.latitude;
longt = coord.longitude;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码来获取用户的当前lat loc.我想更改设备上用户的currentLocation,以查看如何使用注释填充地图.我想模仿应用程序的测试人员在另一个国家/地区的设备上遇到的问题.对于他来说,地图不会加载注释,而对我来说,它在模拟器和设备中工作正常(我们'使用相同的设备型号等).我确实尝试设置currentUserLatitude currentUserLongitude我的测试人员的值,但地图为我添加了注释.
-(void)loadMap{
CLLocationCoordinate2D coordinate = [self getLocation];
currentUserLatitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
currentUserLongitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"*dLatitude : %@", currentUserLatitude);
NSLog(@"*dLongitude : %@",currentUserLongitude);
}
-(CLLocationCoordinate2D) getLocation{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;
}
Run Code Online (Sandbox Code Playgroud) 过去几天我一直在玩Estimote Beacons.我开始怀疑iBeacons的有效性,因为它们在确定Beacons位置时具有很高的延迟.
当你移动2-3米时,它需要几秒钟,直到它的位置正确.一个用例场景,如捕捉一个人走过灯塔的人可能很难确定.
是否可以操作CLLocationManager或CLBeaconRegion的更新/刷新率?例如,每0.1秒
出于某些原因,我希望在不使用委托方法的情况下获取当前位置.
是否有一些解决方案可以从CLLocationManager获取当前位置?
我有一个做地理围栏的应用程序.当我在模拟器(Xcode 8.3.3和Xcode 9)中运行它时,一切似乎都有效,但我的CLLocationManager didEnterRegion永远不会被调用.
当我在iPhone上运行应用程序时,无论是在现实世界中(进入某个区域)还是在Xcode中通过位置模拟运行,它都被称为正常.
知道为什么会这样吗?
我发现的一个区别是模拟器在使用时只支持监控位置,所以我必须设置好所以我的plist文件中有两个权限字符串,但除此之外我感到难过.
由于我不提供代码(它太复杂并且在我的应用程序中分发),让我注意一下模拟器中的工作原理:
在我的应用程序方案中,我选中了"允许位置模拟",并且我已经为我正在监控的位置添加了几个.gpx文件.我有一个默认的位置设置.
我启动时会调用我的位置管理器代理.我得到了.在模拟器中使用了授权者,然后在电话上使用了.
当位置发生变化时,将调用locationManager(:didUpdateLocations :).
当调用didUpdateLocations时,我会执行以下操作:
for r in manager.monitoredRegions {
if let cr = r as? CLCircularRegion {
if cr.contains(location.coordinate) {
log.debug("Am in the region!")
} else {
let crLoc = CLLocation(latitude: cr.center.latitude,
longitude: cr.center.longitude)
log.debug("distance is: \(location.distance(from: crLoc))")
}
}
Run Code Online (Sandbox Code Playgroud)
它的工作原理.所以我的地区受到监控,我的位置就是我认为应该的位置.
最后,没有调用我的locationManager委托的monitoringDidFailFor和didFailWithError.并非他们从来没有 - 他们在开发过程中,但现在不是.
所以我很难过.再次,它在手机上工作正常,而不是在模拟器中.
我究竟做错了什么?
ios ×9
iphone ×4
swift ×4
objective-c ×3
location ×2
mapkit ×2
xcode ×2
coordinates ×1
delegates ×1
google-maps ×1
ibeacon ×1
ios7 ×1