Note that there are some explanatory texts on larger screens.

plurals
  1. POautoupdate a distance between two locations in objective c
    primarykey
    data
    text
    <p>I'm very new to objective-c and have tried several sources to find an answer. No luck so far. Please help me out.</p> <p>I'm building an app with location functionality. The app has to give an alert when a given distance is covered. Therefore I have to save a initial location. When moving the actual position has to be displayed andt the distance as well.</p> <p>What I did is the following:</p> <pre><code>-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { //display latitude NSString *lat =[[NSString alloc]initWithFormat:@"%f", newLocation.coordinate.latitude]; latitude.text=lat; //latr = lat; //display longitude NSString *lon = [[NSString alloc]initWithFormat:@"%f", newLocation.coordinate.longitude]; longitude.text=lon; //longr = lon; //display accuracy //NSString *acc = [[NSString alloc]initWithFormat:@"%f", // newLocation.horizontalAccuracy]; //accuracy.text=acc; } -(void)recordLocation{ double valueLat = [[latitude text]doubleValue]; int latSeconds = valueLat * 3600; int latDegrees = latSeconds / 3600; latSeconds = abs(latSeconds % 3600); int latMinutes = latSeconds / 60; latSeconds %= 60; char latChar = (latitude &gt; 0) ? 'N' : 'S'; double valueLon = [[longitude text]doubleValue]; int lonSeconds = valueLon * 3600; int lonDegrees = lonSeconds / 3600; lonSeconds = abs(lonSeconds % 3600); int lonMinutes = lonSeconds / 60; lonSeconds %= 60; char lonChar = (longitude &gt; 0) ? 'E' : 'W'; CLLocation *tempPos = [[CLLocation alloc] initWithLatitude:valueLat longitude:valueLon]; NSString *recPosition = [[NSString alloc]initWithFormat:@"%i° %i' %i\" %c" " " @"%i° %i' %i\" %c \n", latDegrees, latMinutes, latSeconds, latChar,lonDegrees, lonMinutes, lonSeconds, lonChar]; _labelDegrees.text = recPosition; NSLog(@"%f" , valueLat); NSLog(@"%f" , valueLon); NSLog (@"%@", tempPos); [self distanceFromLocation:tempPos]; } - (CLLocationDistance)distanceFromLocation:(const CLLocation *)tempPos{ double lat1 = [[latitude text] doubleValue]; double lon1 = [[longitude text] doubleValue]; CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:lat1 longitude:lon1]; CLLocationDistance locDistance = [currentLocation distanceFromLocation:tempPos]; NSString *distText = [[NSString alloc]initWithFormat:@"%f", locDistance]; NSLog(@"%@", currentLocation); NSLog(@"%f", locDistance); NSLog(@"%@", distText); [lonDistance setText:distText]; } </code></pre> <p>It workes, but only one time, when I click a Button in my interface.There is no autoupdat of locDistance. The initial location updates automatic (found on the internet), the recording of this position is ok as well. What is wrong in my code. It is possible a simple issue but I'm not able to find the solution.</p> <p>(Please forgive my poor English, I'm dutch)</p> <p>Thank you in advance for your help </p> <p>Regards,</p> <p>Adri </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload