Get Coordinates from Address

by alex 15. February 2010 15:47

 

-(CLLocationCoordinate2D) addressLocation:(NSString *)input {

    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv"

  [input 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;

    return location;

}

 

Tags:

General

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen