我只是想知道如何將地圖視圖作爲用戶靜脈CLLocationmanager和地圖包跟蹤如何中心地圖視圖,同時跟蹤用戶
這是目前我如何跟蹤用戶和更新位置等。
- (void)viewDidLoad
{
// Initialize the TileOverlay with tiles in the application's bundle's resource directory.
// Any valid tiled image directory structure in there will do.
NSString *tileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Tiles"];
TileOverlay *overlay = [[TileOverlay alloc] initWithTileDirectory:tileDirectory];
[map addOverlay:overlay];
// zoom in by a factor of two from the rect that contains the bounds
// because MapKit always backs up to get to an integral zoom level so
// we need to go in one so that we don't end up backed out beyond the
// range of the TileOverlay.
MKMapRect visibleRect = [map mapRectThatFits:overlay.boundingMapRect];
visibleRect.size.width /= 2;
visibleRect.size.height /= 2;
visibleRect.origin.x += visibleRect.size.width/2;
visibleRect.origin.y += visibleRect.size.height/2;
map.visibleMapRect = visibleRect;
// map.showsUserLocation = YES;
//location tracking
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
//Show the users location.. hopefully it works with tracking.
map.showsUserLocation = YES;
[overlay release]; // map is now keeping track of overlay
}
//OverLays Topographical map
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
TileOverlayView *view = [[TileOverlayView alloc] initWithOverlay:overlay];
view.tileAlpha = 0.6;
return [view autorelease];
}
//Tracks Users location and Prints out the Lat and Lon
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D here = newLocation.coordinate;
NSLog(@"%f %f ", here.latitude, here.longitude);
}
我唯一的問題是與你的示例代碼它給我和錯誤與.coordinate說最後一行的「任何成員命名座標CLLocationCoordinate2d「 – 2012-01-17 07:53:51
糟糕,我的錯誤。 '這裏'本身就是一個座標,它會直接工作。 @ C.Johns感謝編輯代碼。 – sElanthiraiyan 2012-01-17 09:37:56
所有的好,有時人們不回來檢查評論等等,所以我認爲我會這樣做,因爲有人使用這個問題來幫助他們可能有任何問題..再次感謝您的幫助。 – 2012-01-17 19:31:32