okudum ve ben şimdiki kullanıcı yerini almak yaparken, aslında orada haritası görsel merkezi haline alamıyorum, AncakBir kullanıcı konumu bilindiğinde veya değiştiğinde MKMapView haritasını görsel olarak nasıl ortalarsınız?
How do I zoom an MKMapView to the users current location without CLLocationManager? yönergeleri takip ettim. Örneğin, viewDidLoad işlevinde, haritanın bilinen konumdaki kullanıcıların çevresinde görsel olarak merkezileşmesine nasıl neden olabilirim? Bu viewDidLoad XXX yoruma bakın (aşağıda CurrentLocation kodu yapıştırdıysanız
sadece MKMapView class aitcenterCoordinate
özelliğini kullanabilirsiniz gibi görünüyor
#import "MapViewController.h"
#import "PlacemarkViewController.h"
@implementation MapViewController
@synthesize mapView, reverseGeocoder, getAddressButton;
- (void)viewDidLoad
{
[super viewDidLoad];
// XXX HERE: How can I cause self.mapView to actually recenter itself at self.mapview.userLocation.location?
mapView.showsUserLocation = YES;
}
- (void)viewDidUnload
{
self.mapView = nil;
self.getAddressButton = nil;
}
- (void)dealloc
{
[reverseGeocoder release];
[mapView release];
[getAddressButton release];
[super dealloc];
}
- (IBAction)reverseGeocodeCurrentLocation
{
self.reverseGeocoder =
[[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
NSString *errorMessage = [error localizedDescription];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Cannot obtain address."
message:errorMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
PlacemarkViewController *placemarkViewController =
[[PlacemarkViewController alloc] initWithNibName:@"PlacemarkViewController" bundle:nil];
placemarkViewController.placemark = placemark;
[self presentModalViewController:placemarkViewController animated:YES];
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
// we have received our current location, so enable the "Get Current Address" button
[getAddressButton setEnabled:YES];
}
@end
Eğer 'mapView.userLocation.coordinate' veya' mapView.userLocation.location.coordinate' ya isteyeyim. CenterCoordinate özelliği, "CLLocationCoordinate2D" türündendir. – Anurag
İyi yakalama, Anurag! Sabit. – Tim
Teşekkürler Guys. Yani self.mapView.centerCoordinate = self.mapView.userLocation.location.coordinate yapıyor; viewDidLoad içinden çalışmaz. Başka bir yerde çalışır (reverseGeocodeCurrentLocation içinde yapıldığı zaman) - DT –