मुझे कैसे पता चलेगा जब एक MKMapView पर setregion regionWillChange / regionDidChange सक्रिय नहीं होगा है

वोट
4

मैं कुछ iPhone MapKit कोड जो कुछ घटनाओं बंद आग पर काम कर रहा हूँ जब नक्शा परिवर्तन की सीमाओं (किसी बाहरी सर्वर मूल रूप से कुछ प्रश्नों के)। वहाँ एक किनारे मामले मैं का समाधान नहीं कर पा रहे है। जब उपयोगकर्ता कोई नया पता दर्ज मैं setRegion का उपयोग करने वाले स्थान पर ज़ूम इन करने के लिए और बाद में मैं नक्शे की सीमा की गणना और उन निर्देशांक के साथ मेरे बाहरी सर्वर क्वेरी। मैं हमेशा setRegion लेकिन कहते हैं, वहाँ एक किनारे मामला है जब यह आग नहीं होगा। यही कारण है कि, एक उपयोगकर्ता जादुई ठीक उसी पते कि, नक्शे की वर्तमान केंद्र में निहित है जब कि नक्शा बिल्कुल वैसा ही क्षेत्र के लिए ज़ूम इन करता है का चयन करने के होता है जब। बेशक यह संभावना बहुत कम होता है, लेकिन यह प्राप्त आसान निम्न कोड के साथ है:

CLLocation *centerOfMap = [[CLLocation alloc] initWithLatitude:mapView.centerCoordinate.latitude longitude:mapView.centerCoordinate.longitude];
mySearchLocation.searchLocation = centerOfMap;

//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:YES];

यह वर्तमान नक्शे के केंद्र में एक पिन ड्रॉप और उस के आधार पर अपने सर्वर के लिए एक क्वेरी बंद आग उपयोगकर्ता की अनुमति के बराबर होगा। दुर्भाग्य से, क्योंकि कोड तर्क क्षेत्र बदल रहा है (जो मैं इतना है कि उपयोगकर्ताओं को आसानी से नक्शे के आसपास पैन कर सकते हैं और स्पष्ट रूप से एक ताज़ा करें बटन दबाने की जरूरत नहीं किया है) पर निर्भर करता है, मैं चारों ओर एक काम की जरूरत है। मुझे कैसे पता कर सकते हैं जब setRegion बुलाया गया है, लेकिन यह regionWillChange / regionDidChange सक्रिय नहीं होगा। मैं समारोह कुछ कैसे ओवरराइड कर सकते हैं?

संपादित करें: जैसा कि मैंने पहले उत्तर पर टिप्पणी की, मैं पता लगाने के लिए जब इस क्षेत्र निम्नलिखित कोड का उपयोग करके परिवर्तन नहीं होगा करने की कोशिश की:

//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;
region = [mapView regionThatFits:region]; //Not sure if this is necessary

NSLog(@diff in latitude of center %f, (mapView.region.center.latitude - region.center.latitude));
NSLog(@diff in longitude of center %f, (mapView.region.center.longitude - region.center.longitude));
NSLog(@diff in latitude span %f, (mapView.region.span.latitudeDelta - region.span.latitudeDelta));
NSLog(@diff in longitude span %f, (mapView.region.span.longitudeDelta - region.span.longitudeDelta));

[self.mapView setRegion:region animated:YES];

दुर्भाग्य से, जब मैं searchLocation सेट वर्तमान मानचित्र मैं निम्नलिखित परिणाम प्राप्त के केंद्र होने के लिए:

diff in latitude of center 0.000000
diff in longitude of center 0.000016
diff in latitude span -0.000000
diff in longitude span 0.000000

विभिन्न मामलों में त्रुटि थोड़ा अलग लेकिन आम तौर पर भाषी क्षेत्र इस setRegion या morever, regionDidChange, आग नहीं है थोड़ा अलग है, तब भी जब है। किसी को भी बताएगा कि ऐसा क्यों कर सकते हैं? या कैसे मैं इस को ठीक से पता लगाने के बारे में जा सकते हैं। नोट: मैं भी mapView.centerCoordinate साथ करने की कोशिश की, लेकिन मैं इसी तरह की त्रुटियों मिलता है, और मैं केवल पता करने के लिए जब इस क्षेत्र में बदलाव नहीं होगा (अगर centerCoordinate ही है ज़ूम स्तर / क्षेत्र अभी भी अलग हो सकता है) चाहते हैं।

18/01/2010 को 19:02
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


3 जवाब

वोट
0

निम्नलिखित कोड मेरे लिए काम करता है:

    let predictRect = mapView.convertRegion(mapView.regionThatFits(THE_REGION_YOU_WANT_TO_SET), toRectTo: mapView)

    if predictRect.origin.x.rounded() == 0 && predictRect.origin.y.rounded() == 0
        && predictRect.size.width.rounded() == mapView.bounds.width
        && predictRect.size.height.rounded() == mapView.bounds.height
    {
        debugPrint("setRegion same, will not trigger region change event")
    }
18/04/2017 को 16:41
का स्रोत उपयोगकर्ता

वोट
0

यह एक हैक की गई वैकल्पिक हल मेरे लिए अच्छी तरह से काम करने लगता है कि है।

MKCoordinateRegion currentRegion = mapView.region;

// Capture the instances where setRegion will not be fired
BOOL regionLatitudeSame = (int)(currentRegion.center.latitude*1000000) == (int)(region.center.latitude*1000000);
BOOL regionLongitudeSame = (int)(currentRegion.center.longitude*1000000) == (int)(region.center.longitude*1000000);
BOOL regionSame = regionLatitudeSame && regionLongitudeSame;
if (regionSame)
{
    // Safe to assume that regionWillChange/regionDidChange WON'T be called
}

आप शायद देखा है के रूप में, मैं इस धारणा है कि छठे दशमलव स्थान के बाद सटीकता अभी तक भी नगण्य है (बनाया है 11 मिमी अप करने के लिए (यहां तक कि अपने उच्चतम ज़ूम स्तर पर)) एक दृश्य को बदलने के लिए नक्शे पर आवश्यक होने की।

30/09/2012 को 12:14
का स्रोत उपयोगकर्ता

वोट
0

आप क्यों नहीं बस कॉल नहीं करते regionWill / कोड है कि नया नक्शा स्थान स्थापित कर रही है से मैन्युअल रूप से परिवर्तन किया था अगर यह बात यह नक्शा स्थापित करेगा वर्तमान केंद्र होगा पता लगाता है?

18/01/2010 को 21:20
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more