2010-03-09 13 views
6

कोई भी ट्रिगर या जीपीएस विशेषज्ञ यहां मेरी मदद कर सकते हैं? मैं एक भू--स्थानिक बाउंडिंग बॉक्स (आयताकार) गणना बनाने की कोशिश कर रहा हूं जो मैंने प्राप्त की गई निम्न विधि का उपयोग करके अधिकतम अक्षांश और देशांतर को वापस कर रहा है। मैं प्रत्येक बार बीयरिंग के लिए विधि को बुला रहा हूं: उत्तर, दक्षिण, पूर्व और पश्चिम। इन चार मूल्यों के साथ मैं बॉक्स के भीतर सभी ऑब्जेक्ट्स के लिए अपने कोर डेटा स्टोर से पूछताछ करना चाहता हूं।भू स्पेस बाउंडिंग बॉक्स आयताकार गणना त्रुटि: अक्षांश गलत

-(CLLocation*) offsetLocation:(CLLocation*)startLocation:(double)offsetMeters:(double)bearing { 


    double EARTH_MEAN_RADIUS_METERS = 6372796.99; 
    double newLatitude = asin(sin(startLocation.coordinate.latitude) * cos(offsetMeters/EARTH_MEAN_RADIUS_METERS) + cos(startLocation.coordinate.latitude) * sin(offsetMeters/EARTH_MEAN_RADIUS_METERS) * cos(bearing)); 
    double newLongitude = startLocation.coordinate.longitude + atan2(sin(bearing) * sin(offsetMeters/EARTH_MEAN_RADIUS_METERS) * cos(startLocation.coordinate.latitude), cos(offsetMeters/EARTH_MEAN_RADIUS_METERS) - sin(startLocation.coordinate.latitude) * sin(newLatitude)); 


    CLLocation *tempLocation = [[CLLocation alloc] initWithLatitude:newLatitude longitude:newLongitude]; 
    [tempLocation autorelease]; 
    return tempLocation; 
} 

समस्या यह है कि नए अक्षांश ऑफ़सेट की गणना निश्चित रूप से गलत है।

startLocation: अक्षांश 37.331688999999997, देशांतर -१२२.०,३०,७३१ offsetMeters: 1000 असर: 0 (उत्तर)

newLatitude रिटर्न -0.36726592610659514 (गलत) निम्नलिखित को देखते हुए।

कोई सुझाव? मैंने अभी तक इस विशेष सूत्र के चारों ओर कोड किया है और यह मुझे स्टंप कर चुका है। मैंने PHP से किसी भी फॉर्मूला का अनुवाद करने का भी प्रयास नहीं किया है। मुझे लगता है कि उपर्युक्त वही है जो मुझे चाहिए अगर इसे tweaked किया जा सकता है।

धन्यवाद, b.dot

उत्तर

13

मैं अपने कोड को देखा नहीं है, लेकिन आप भी MapKit समारोह MKCoordinateRegionMakeWithDistance() इस्तेमाल कर सकते हैं रूपरेखा है आप के लिए बाउंडिंग बॉक्स की गणना।

CLLocationCoordinate2D center = { 37.3, -122.0 }; 
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 2000.0, 2000.0); 
CLLocationCoordinate2D northWestCorner, southEastCorner; 
northWestCorner.latitude = center.latitude - (region.span.latitudeDelta/2.0); 
northWestCorner.longitude = center.longitude + (region.span.longitudeDelta/2.0); 
southEastCorner.latitude = center.latitude + (region.span.latitudeDelta/2.0); 
southEastCorner.longitude = center.longitude - (region.span.longitudeDelta/2.0); 
+0

वाह। मैं MapKit का उपयोग नहीं कर रहा हूं, इसलिए मैंने वहां देखने का विचार नहीं किया था। धन्यवाद। मैं दोनों तरीकों का प्रयास करने जा रहा हूँ। –

+0

MKCoordinateRegionMakeWithDistance बहुत अच्छा बॉक्स बनाता है, हालांकि मुझे यकीन नहीं है कि नए बनाए गए क्षेत्र की सीमाओं (अधिकतम अक्षांश या देशांतर) को कैसे पुनर्प्राप्त किया जाए। सभी गुण MapView से संबंधित प्रतीत होते थे। –

+0

यह सिर्फ थोड़ा गणित है, है ना? मैंने अपने जवाब में कुछ कोड जोड़ा। ध्यान दें कि यदि यह कोड दिनांक रेखा या ध्रुवों को पार करता है तो यह कोड काम नहीं करता है। लेकिन फिर, आपको डेटा स्टोर से पूछताछ करने के लिए इसे किसी भी बॉक्स में विभाजित करने की आवश्यकता होगी। –

1

CLLocationCoordinate2D भंडार डिग्री में निर्देशांक, लेकिन ट्रिग कार्यों का उपयोग कर रहे रेडियन इकाइयों की आवश्यकता है। यदि आप रेडियंस में कनवर्ट करते हैं (M_PI/180, या 0.017453293f द्वारा गुणा करें), तो यह शायद काम करेगा।

+0

धन्यवाद ब्रायन। में इसे याद रखूंगा। –

1

आप लोग एनएसपीडिकेटेट्स कैसे स्थापित कर रहे हैं?

मुझे लगता है कि मेरे साथ प्रदर्शन के मुद्दों में भाग लेते हैं।

NSPredicate *northWestLat = [NSPredicate predicateWithFormat:@"ANY locations.lat > %lf", northWestCorner.latitude]; 
NSPredicate *southhWestLat = [NSPredicate predicateWithFormat:@"ANY locations.lat < %lf", southEastCorner.latitude]; 
NSPredicate *latitudePredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:northWestLat, southhWestLat, nil]]; 

NSPredicate *northWestLng = [NSPredicate predicateWithFormat:@"ANY locations.lng < %lf", northWestCorner.longitude]; 
NSPredicate *southEastLng = [NSPredicate predicateWithFormat:@"ANY locations.lng > %lf", southEastCorner.longitude]; 
NSPredicate *longitudePredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:northWestLng, southEastLng, nil]]; 

NSPredicate *coordPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:latitudePredicate, longitudePredicate, nil]]; 
+2

आप किसी का उपयोग क्यों कर रहे हैं? क्यों न केवल [[एनएसपीडिकेट predicateWithFormat: @ "अक्षांश>% एफ और अक्षांश <% एफ और देशांतर>% एफ और देशांतर <% एफ", latMin, latMax, lngMin, lngMax]; ' –

संबंधित मुद्दे