/ Published in: Objective C
This is the code i wrote for clubplanet to get the distance from the user's location to the venues.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Get the distance from the user's location to the venue CLLocation *userLoc = [[CLLocation alloc] initWithLatitude:userLocation.latitude longitude:userLocation.longitude]; CLLocationCoordinate2D venueCoord = [self addressLocation:venueAddress]; CLLocation *venueLoc = [[CLLocation alloc] initWithLatitude:venueCoord.latitude longitude:venueCoord.longitude]; double dist = [userLoc getDistanceFrom:venueLoc] / 1609.344; //NSLog(@"%.2f miles", dist); #pragma mark addressLocation //method to convert address to longitude and latitude [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; double _latitude = 0.0; double _longitude = 0.0; if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) { _latitude = [[listItems objectAtIndex:2] doubleValue]; _longitude = [[listItems objectAtIndex:3] doubleValue]; } else { //Show error } CLLocationCoordinate2D _location; _location.latitude = _latitude; _location.longitude = _longitude; //NSLog(@"%f - %f", latitude, longitude); return _location; }