Return to Snippet

Revision: 23355
at February 4, 2010 16:51 by espinallab


Initial Code
//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);
		
		lblapproxdistance.text = [NSString stringWithFormat:@"%.1f miles",dist];





#pragma mark addressLocation

//method to convert address to longitude and latitude
-(CLLocationCoordinate2D) addressLocation:(NSString *)address {
    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv&key=ABQIAAAA-d08Ko4-kHQWa1zY6Y4n2BQJqvlAqZSQuvHwEwe-mLrrdxxNhxRp0156iscZ4xaIZTeX_4YwLHlJEA", 
						   [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
    NSArray *listItems = [locationString componentsSeparatedByString:@","];
	
    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;
}

Initial URL

                                

Initial Description
This is the code i wrote for clubplanet to get the distance from the user's location to the venues.

Initial Title
Get the distance from the user's location to the venue

Initial Tags

                                

Initial Language
Objective C