CLLocationCoordinate2D cordinate = [self geoCodeUsingAddress:@"
6138 Bollinger Road, San Jose, United States"];
NSLog(@"coordinate from address::%f , %f",cordinate.longitude,cordinate.latitude);
- (CLLocationCoordinate2D) geoCodeUsingAddress:(NSString *)address
{
CLGeocoder *geocoder11 = [[CLGeocoder alloc] init];
[geocoder11 geocodeAddressString: address completionHandler:^(NSArray* placemarks, NSError* error){
for (CLPlacemark* aPlacemark in placemarks)
{
// Process the placemark.
NSString *latDest1 = [NSString stringWithFormat:@"%.4f",aPlacemark.location.coordinate.latitude];
NSString *lngDest1 = [NSString stringWithFormat:@"%.4f",aPlacemark.location.coordinate.longitude];
NSLog(@"coordinate from address::%@ , %@",latDest1,lngDest1);
CLLocationCoordinate2D center;
center.latitude = aPlacemark.location.coordinate.latitude;
center.longitude = aPlacemark.location.coordinate.longitude;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 50, 50);
region.span.latitudeDelta = 0.02f;
region.span.longitudeDelta = 0.02f;
region.center = center;
[self.myMapView setRegion:region animated:YES];
//set annotation
MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init];
NSString *sttt = [[NSString alloc]initWithFormat:@"%f,%f",center.latitude,center.longitude];
annotation.title = address;
annotation.subtitle = sttt;
annotation.coordinate = center;
[self.myMapView addAnnotation:annotation];
return center;
}
}];
}
No comments:
Post a Comment