简体   繁体   中英

Load Google Map Directly to specified Address in iPhone

如何通过用户在UItextField中加载Google Map-特定区域地图-指定地址?

Ok. I Got the solution by r&d.

See the code following.

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM