سؤال

لدي الحلقة التالية في LeyDiddload:

    for(int i=1; i<[eventsArray count]; i++) {
  NSArray *componentsArray = [[eventsArray objectAtIndex:i] componentsSeparatedByString:@","];
  if([componentsArray count] >=6) {
   Koordinate *coord = [[Koordinate alloc] init];
   coord.latitude = [[componentsArray objectAtIndex:0] floatValue];
   coord.longtitude = [[componentsArray objectAtIndex:1] floatValue];
   coord.magnitude = [[componentsArray objectAtIndex:2] floatValue];
   coord.depth = [[componentsArray objectAtIndex:3] floatValue];
   coord.title = [componentsArray objectAtIndex:4];
   coord.strasse = [componentsArray objectAtIndex:5];
   coord.herkunft = [componentsArray objectAtIndex:6];
   coord.telefon = [componentsArray objectAtIndex:7];
   coord.internet = [componentsArray objectAtIndex:8];
   [eventPoints addObject:coord];


  }

التنسيق هو cllocationCoordinate2d

ولكن كيف يمكنني استخدام CONSOR في الطريقة التالية ، لأنني أحتاج إلى الحصول على المسافة بين تنسيقين:

    - (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation{

}

الرجاء مساعدتي أنا تقطعت بهم السبل!

شكرا لكم جميعا على المساعدة مسبقا

هل كانت مفيدة؟

المحلول

CLLocation لديه طريقة init اسمها -(id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude. ثم استخدام - (CLLocationDistance)getDistanceFrom:(const CLLocation *)location للحصول على المسافة بين كائنين cllocation.

نصائح أخرى

بسيط

CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lon];

للحشد السريع ،

لدي طريقة تسمى "FetchCafesArroundLocation" التي يتم تحديثها بعد تحريك الخريطة. هذه هي الطريقة التي تعاملت بها مع الحصول على LAT و LON في cllocation من cllocationCoordiate2D ثم نقلت متغير CLLOCATION إلى طريقة المناولة.

func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool){

    var centre = mapView.centerCoordinate as CLLocationCoordinate2D

    var getLat: CLLocationDegrees = centre.latitude
    var getLon: CLLocationDegrees = centre.longitude


    var getMovedMapCenter: CLLocation =  CLLocation(latitude: getLat, longitude: getLon)

    self.lastLocation = getMovedMapCenter
    self.fetchCafesAroundLocation(getMovedMapCenter)

}

"كيف يمكنني استخدام مثيلتي كـ cllocation؟"

لا يمكنك ذلك ، لأنها ليست واحدة. أنت بحاجه إلى اصنع واحدا.

لا تنسى أن تطلق ما تقوم بخصائصه. نرى قواعد إدارة الذاكرة.

إذا كان التنسيق أ CCLocationCoordinate2D, ، ثم يمكنك تعيين تحديد الموقع من

**- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation**

تفويض بالحصول على كل من latitude و longitude خصائص خاصية تنسيق CLLocation على النحو التالي:

coord.latitude = newLocation.coordinate.latitude;
coord.longitude = newLocation.coordinate.longitude;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top