2012-03-06 6 views
0

J'avais une application qui fonctionnait bien jusqu'à ce que j'ai mis à jour à iOS 5.0. Après la mise à jour de la carte est affichée dans l'océan. Je ne suis pas sûr de ce qui a mal tourné. Voici le code que j'utiliseMapView montrant dans l'océan dans ios 5

[mapView setMapType: MKMapTypeStandard];

[mapView setZoomEnabled:YES]; 
[mapView setScrollEnabled:YES]; 
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
region.center.latitude = deleg.selectedVenue.latitude; 
region.center.longitude = deleg.selectedVenue.longitude; 
region.span.longitudeDelta = 0.01f; 
region.span.latitudeDelta = 0.01f; 
[mapView setRegion:region animated:YES]; 

Comment puis-je faire cela correctement dans ios 5.0? Merci

+2

Comment et où est défini deleg.selectedVenue? Quelle méthode utilise ce code? Ce var est probablement nul ici pour une raison quelconque. – Anna

Répondre

0

Voici un extrait de code qui fonctionne sous iOS5. N'hésitez pas à poser des questions.

// grab the location from persistent store 
CLLocation *loc = [store currentLocation]; 


CLLocationCoordinate2D zoomLocation; 
float zoom; 

// it will be NULL on first launch, so initialize to someplace interesting. 
if (!loc) { 
    CLLocationCoordinate2D longPointLightLocation; 
    longPointLightLocation.latitude = 42.033126; 
    longPointLightLocation.longitude = -70.168621; 
    // center the map so the initial zoom when the GPS kicks in is from HERE, not the default 
    [mapView setCenterCoordinate:longPointLightLocation animated:NO]; 
    zoomLocation = longPointLightLocation; 
    zoom = 50; // on first launch, zoom way out 
} else { 
    zoomLocation.latitude = loc.coordinate.latitude; 
    zoomLocation.longitude = loc.coordinate.longitude; 
    zoom = 2; 
} 

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, zoom*METERS_PER_MILE, zoom*METERS_PER_MILE); 
[mapView setRegion:[mapView regionThatFits:viewRegion] animated:NO]; 
0

Vérifiez que deleg.selectedVenue est une coordonnée valide, par ex. Où CLLocationCoordinate2DIsValid est une fonction déclarée dans l'infrastructure d'emplacement principal.