2009-08-10 10 views

答えて

3

私は解決策を見つけましたr & d。

次のコードを参照してください。

-(IBAction)showAddress // after adding the Address into textField - button pressed{ 
[addressField resignFirstResponder]; 
MKCoordinateRegion region; 
MKCoordinateSpan span; 
span.latitudeDelta=0.05; 
span.longitudeDelta=0.05; 
CLLocationCoordinate2D location = [self addressLocation]; 
region.span=span; 
region.center=location; 
if(addAnnotation != nil) 
{ 
    [mapView removeAnnotation:addAnnotation]; 
    [addAnnotation release]; 
    addAnnotation=nil; 
} 
addAnnotation = [ [AddressAnnotation alloc] initWithCoordinate:location]; 
[mapView setRegion:region animated:TRUE]; 
[mapView regionThatFits:region]; 
[mapView addAnnotation:addAnnotation]; 

}

-(CLLocationCoordinate2D) addressLocation { 
// NSString *urlString = [[NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",[addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
NSString *urlString=[NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",[addressField.text 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 
{ 
    NSLog(@"Error"); 
} 
CLLocationCoordinate2D location; 
location.latitude=latitude; 
location.longitude=longitude; 
return location; 

}

関連する問題