DJH*_*ard 11 iphone location zooming mkmapview
我似乎与许多发布在这里的人有相反的问题MKMapView.我似乎无法让它停止这样做,而不是无法让它缩放并显示当前位置.这是发生的事情:
我试图告诉我CLLocationManager到stopUpdatingLocation(没有任何影响,因为一个MKMapView知道如何使用CoreLocation),我尝试了告诉MKMapView给setShowsUserLocation:NO(无蓝点显示在所有的,这不是我想要的).我甚至试图消除我的CLLocationManager(没有效果).造成这种情况的原因是什么?如何阻止它?
是的,我确实设置了位置管理员的准确性和距离-loadView.
我没有实施-mapViewDidFinishLoadingMap:.这是我的实施
-locationManager:didUpdateToLocation:fromLocation:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// How many seconds ago was this new location created?
NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];
// CLLocationManagers will return the last found location of the device first,
// you don't want that data in this case. If this location was made more than 3
// minutes ago, ignore it.
if (t < -180)
{
// This is cached data, you don't want it, keep looking
return;
}
[locationManager stopUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)
我认为这是你要问的中心,@ Anna娜Karenina:
- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)u
{
CLLocationCoordinate2D loc = [u coordinate];
// Display the region 500 meters square around the current location
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 500, 500);
[mv setRegion:region animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
首先,我不知道这会对事情产生多大影响,但是您是否在viewDidLoad(或在您实现 locationManager 的任何地方)中设置了位置管理器的准确性和距离过滤器:
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
Run Code Online (Sandbox Code Playgroud)
其次,检查源代码中的这两个函数(忽略我在此处列出的实际函数的内容,它只是为了说明和显示用法),如果可能,请提供这些函数的代码,以便我们可以更好地提供帮助:
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
[activityIndicator stopAnimating];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSDate* eventDate = newLocation.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0)
{
NSLog(@"New Latitude %+.6f, Longitude %+.6f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4200 次 |
| 最近记录: |