Xcode for distance between two locations in google maps [duplicate]
Possible Duplicate:
Calculate distance between two locations using google map in iphone
I just want to complete xcode for calculate distance between two location . In which user can enter both the location's addresses, and from that addresses I want to calculate the distance between them b,coz am new to xcode. Please send a link/code as soon as possible Thank you
From addresses you have to take the latitude and longitudes. like this
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", theAddress];
NSString *locationString = [[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]] autorelease];
NSArray *splitArray = [[[NSArray alloc] initWithArray:[locationString componentsSeparatedByString:@","]] autorelease];
if([splitArray count]!=0)
{
MKCoordinateRegion region;
region.center.latitude = [[splitArray objectAtIndex:2] doubleValue];
region.center.longitude = [[splitArray objectAtIndex:3] doubleValue];
region.span.latitudeDelta = 0.01; // Add a little extra space on the sides
region.span.longitudeDelta = 0.01; // Add a little extra space on the sides
region = [mapView regionThatFits:region];
[mapView setRegion:region animated:YES];
CLLocation *firstLocation= [[CLLocation alloc]initWithLatitude:[[splitArray objectAtIndex:2] doubleValue] longitude:[[splitArray objectAtIndex:3] doubleValue]];
//in the sameway for secondlocation also
CLLocationDistance distance = [firstLocation distanceFromLocation:secondLocation];
精彩评论