I m mit MapKit in meiner Anwendung und disaply den Standort des Nutzers mit
[mapview setShowUserLocation:YES];
Ich mag die region.center.latitude und region.center.longitude mit der Koordinate des userLocation setzen, wie es zu tun?
I m mit MapKit in meiner Anwendung und disaply den Standort des Nutzers mit
[mapview setShowUserLocation:YES];
Ich mag die region.center.latitude und region.center.longitude mit der Koordinate des userLocation setzen, wie es zu tun?
Hier ist meine Antwort, ich versuche, so etwas und seine Arbeits:
//inside my ViewDidLOad
locManager = [[CLLocationManager alloc] init];
[locManager setDelegate:self];
[locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locManager startUpdatingLocation];
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D loc = [newLocation coordinate];
[maptView setCenterCoordiante:loc];
}
Viel einfacher:
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 1500, 1500);
[mapView setRegion:region animated:YES];
}
Aus irgendeinem Grund, dies für mich nicht funktioniert hat. Es nimmt mich auf die Koordinaten (0.0000, 0.0000). Unten ist mein Code, wenn Sie eine Chance zu überprüfen, es haben wird. Danke für die Hilfe!
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
mapView.showsUserLocation=TRUE;
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
CLLocationCoordinate2D myCoord = {mapView.userLocation.location.coordinate.latitude,mapView.userLocation.location.coordinate.longitude};
[mapView setCenterCoordinate:myCoord animated:YES];
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
Ich denke , das beantwortet Ihre Frage: Rückkehr MapKit Userlocation Koordinaten
(nutzt den mapView.userLocation.location.coordinate.latitudeund mapView.userLocation.location.coordinate.longitude properties)
und dann diese Koordinaten in das injizieren
-(void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated
Ihre MKMapView Instanz.
Mit Delegierten:
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 500, 500); [mapView setRegion:region animated:YES]; }
Ohne Delegierten:
[self.mapView setuserTrackingMode:MKUserTrackingModeFollow];