开发者

Xcode for distance between two locations in google maps [duplicate]

开发者 https://www.devze.com 2023-04-08 14:44 出处:网络
This question already has an answer here:开发者_如何学Python Closed 11 years ago. Possible Duplicate:
This question already has an answer here: 开发者_如何学Python Closed 11 years ago.

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];

0

精彩评论

暂无评论...
验证码 换一张
取 消