2010-01-17 15 views
18

मैं अपने एमकेमैप व्यू पर एक क्षेत्र सेट करना चाहता हूं और फिर नक्शे के पूर्वोत्तर और एसडब्ल्यू कोने से संबंधित निर्देशांक ढूंढना चाहता हूं।मुझे कैसे पता चलेगा कि MKMapview setRegion: एनिमेटेड: समाप्त हो गया है?

This code works just fine to do that: 
//Recenter and zoom map in on search location 
MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}}; 
region.center = mySearchLocation.searchLocation.coordinate; 
region.span.longitudeDelta = 0.01f; 
region.span.latitudeDelta = 0.01f; 
[self.mapView setRegion:region animated:NO]; //When this is set to YES it seems to break the coordinate calculation because the map is in motion 

//After the new search location has been added to the map, and the map zoomed, we need to update the search bounds 
//First we need to calculate the corners of the map so we get the points 
CGPoint nePoint = CGPointMake(self.mapView.bounds.origin.x + mapView.bounds.size.width, mapView.bounds.origin.y); 
CGPoint swPoint = CGPointMake((self.mapView.bounds.origin.x), (mapView.bounds.origin.y + mapView.bounds.size.height)); 

//Then transform those point into lat,lng values 
CLLocationCoordinate2D neCoord; 
neCoord = [mapView convertPoint:nePoint toCoordinateFromView:mapView]; 
CLLocation *neLocation = [[CLLocation alloc] initWithLatitude:neCoord.latitude longitude:neCoord.longitude]; 

CLLocationCoordinate2D swCoord; 
swCoord = [mapView convertPoint:swPoint toCoordinateFromView:mapView]; 
CLLocation *swLocation = [[CLLocation alloc] initWithLatitude:swCoord.latitude longitude:swCoord.longitude]; 

समस्या यह है कि मैं नक्शा ज़ूम एनिमेटेड होना चाहता हूं। हालांकि, जब मैं सेटरेगियन सेट करता हूं: YES के लिए एनिमेटेड, मैं मानचित्र से निर्देशांक प्राप्त करता हूं जब यह ज़ूम आउट हो जाता है (यानी, एनीमेशन पूरा होने से पहले)। क्या सिग्नल प्राप्त करने का कोई तरीका है कि एनीमेशन किया जाता है?

उत्तर

21

कभी भी नक्शाकिट का उपयोग नहीं किया गया था, लेकिन MKMapViewDelegate में एक विधि है mapView:regionDidChangeAnimated: जो आप देख रहे हैं।

+0

मुझे बेवकूफ, यह प्रतिनिधि प्रोटोकॉल नहीं MKMapView अपने आप में किया गया था। मुझे पता था कि मैंने इसे कहीं देखा था ... धन्यवाद: डी – deadroxy

4

मुझे पता है कि यह बहुत पुराना है, लेकिन अगर किसी और के उत्तर की तलाश में आता है, तो यहां एक विकल्प है।

इस संस्करण के बारे में अच्छी बात यह है कि आप कॉलबैक विधि में अनुमान लगाने/हार्डकोडिंग के बजाए पहले पूर्ण होने पर एक पूर्णता पूर्णता को चला सकते हैं क्योंकि उसे तुरंत कॉल किया जाता है।

[MKMapView animateWithDuration:1.0 animations:^{ 
    [mapView setRegion:mapRegion animated:YES]; 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:1.0 animations:^{ 
     self.mapDotsImageView.alpha = 1.0; 
    }]; 
}]; 

या सिर्फ

// zoom in... 
let km3:CLLocationDistance = 3000 
let crTight = MKCoordinateRegionMakeWithDistance(location.coordinate, km3, km3) 
MKMapView.animate(withDuration: 1.0, animations: { self.theMap.region = crTight }) 
संबंधित मुद्दे