Frage

Ich habe die folgende Schleife in meiner ViewDIDLOAD:

    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];


  }

Koord ist cllocationCoordinate2d

Aber wie kann ich die Koordination in der folgenden Methode verwenden, da ich dies benötige, um einen Abstand zwischen zwei Koordnungen zu erhalten:

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

}

Bitte hilf mir, ich bin gestrandet!

Vielen Dank, dass Sie vorher geholfen haben

War es hilfreich?

Lösung

CLLocation hat eine Init -Methode mit dem Namen -(id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude. Dann benutze - (CLLocationDistance)getDistanceFrom:(const CLLocation *)location Um den Abstand zwischen zwei Cllocationsobjekten zu erhalten.

Andere Tipps

Einfach

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

Für die schnelle Menge,

Ich habe eine Methode namens "FetchcafesarroundLocation", die nach dem Umgang mit der Karte aktualisiert wird. Auf diese Weise habe ich damit umgegangen, die Lat und Lon in Cllocation von CllocationCoordiate2D zu bringen und dann die Cllocationsvariable an die Handhabungsmethode zu übergeben.

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)

}

"Wie kann ich meine Instanz als Cllocation verwenden?"

Du kannst nicht, weil es keines ist. Du musst erstelle einen.

Vergessen Sie nicht, das zu veröffentlichen, was Sie Alloc haben. Sehen Die Speicherverwaltungsregeln.

Wenn die Koordung a ist CCLocationCoordinate2D, dann können Sie die Newlocation von der zuweisen

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

delegieren, indem Sie beide bekommen latitude und longitude Eigenschaften der Koordinateneigenschaft des CLLocation wie nachstehend:

coord.latitude = newLocation.coordinate.latitude;
coord.longitude = newLocation.coordinate.longitude;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top