Friday 27 July 2012

Get latitude and longitude from a full address (street, city, etc.) input by the user



you can get latitude and longitude from a full address (street, city, etc.) input by the user

- (CLLocationCoordinate2D) geoCodeUsingAddress:(NSString *)address
{
    double latitude = 0, longitude = 0;
    NSString *esc_addr =  [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];
    NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
    if (result) {
        NSScanner *scanner = [NSScanner scannerWithString:result];
        if ([scanner scanUpToString:@"\"lat\" :" intoString:nil] && [scanner scanString:@"\"lat\" :" intoString:nil]) {
            [scanner scanDouble:&latitude];
            if ([scanner scanUpToString:@"\"lng\" :" intoString:nil] && [scanner scanString:@"\"lng\" :" intoString:nil]) {
                [scanner scanDouble:&longitude];
            }
        }
    }
    CLLocationCoordinate2D center;
    center.latitude = latitude;
    center.longitude = longitude;
    return center;
}

Friday 20 July 2012

Loading View with Grayed View...

For Global Display the LoadingView we use some control and we declare this view with our custom Method.And also we declare these method in AppDelegate so we can use this loading view Globally.

-First We Declare Control in AppDelegate.h file


@interface AppDelegate : UIResponder <UIApplicationDelegate>{
           UIView *activityView;
           UIView *loadingView;
           UILabel *lblLoad;
}
-(void) showLoadingView;
-(void) showLoadingViewForWebView;
-(void) hideLoadingView;



After that Just put bellow code in AppDelegate.m file


#pragma mark - Loading View
-(void) showLoadingView {
//NSLog(@"show loading view called");
if (loadingView == nil) {
        
        loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 60.0, 320.0, 420.0)];
        loadingView.opaque = NO;
        loadingView.backgroundColor = [UIColor darkGrayColor];
        loadingView.alpha = 0.5;
UIView *subloadview=[[UIView alloc] initWithFrame:CGRectMake(84.0, 190.0,150.0 ,50.0)];
        subloadview.backgroundColor=[UIColor blackColor];
subloadview.opaque=NO;
subloadview.alpha=0.8;
subloadview.layer.masksToBounds = YES;
subloadview.layer.cornerRadius = 6.0;
lblLoad=[[UILabel alloc]initWithFrame:CGRectMake(50.0, 7.0,80.0, 33.0)];
lblLoad.text=@"LoadingView";
lblLoad.backgroundColor=[UIColor clearColor];
lblLoad.textColor=[UIColor whiteColor];
[subloadview addSubview:lblLoad];
        UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
        [spinningWheel startAnimating];
        spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
        [subloadview addSubview:spinningWheel];
[loadingView addSubview:subloadview];
        [spinningWheel release];
    }       
    [self.window addSubview:loadingView];
//[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}

-(void) showLoadingViewForWebView {
//NSLog(@"show loading view called");
if (loadingView == nil) {
        loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
        loadingView.opaque = NO;
        loadingView.backgroundColor = [UIColor darkGrayColor];
        loadingView.alpha = 0.5;
UIView *subloadview=[[UIView alloc] initWithFrame:CGRectMake(84.0, 175.0,150.0 ,50.0)];
        subloadview.backgroundColor=[ UIColor blackColor];
subloadview.opaque=NO;
subloadview.alpha=0.8;
subloadview.layer.masksToBounds = YES;
subloadview.layer.cornerRadius = 6.0;
lblLoad=[[UILabel alloc]initWithFrame:CGRectMake(50.0, 7.0,80.0, 33.0)];
lblLoad.text=@"LoadingView";
lblLoad.backgroundColor=[UIColor clearColor];
lblLoad.textColor=[UIColor whiteColor];
[subloadview addSubview:lblLoad];
        UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
        [spinningWheel startAnimating];
        spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
        [subloadview addSubview:spinningWheel];
[loadingView addSubview:subloadview];
        [spinningWheel release];
    }       
    [self.window addSubview:loadingView];
//[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}

-(void) hideLoadingView {
if (loadingView) {
        [loadingView removeFromSuperview];
        [loadingView release];
        loadingView = nil;
    }
    
}

Wednesday 18 July 2012

Get Selected Row of PickerView...


- (IBAction) showAlert {
    NSUInteger numComponents = [[myPickerView datasource] numberOfComponentsInPickerView:myPickerView];
    
    NSMutableString * text = [NSMutableString string];
    for(NSUInteger i = 0; i < numComponents; ++i) {
        NSUInteger selectedRow = [myPickerView selectedRowInComponent:i];
        NSString * title = [[myPickerView delegate] pickerView:myPickerView titleForRow:selectedRow inComponent:i];
        [text appendFormat:@"Selected item \"%@\" in component %lu\n", title, i];
    }
    
    NSLog(@"%@", text);
}

Thursday 12 July 2012

Map View Zoom out with all Annotaion pin...


-(void)zoomToFitMapAnnotations:(MKMapView*)mapView
{
    if([mapView.annotations count] == 0)
        return;
    
    BOOL testing=NO;
    CLLocationCoordinate2D topLeftCoord;
    topLeftCoord.latitude = -90;
    topLeftCoord.longitude = 180;
    
    CLLocationCoordinate2D bottomRightCoord;
    bottomRightCoord.latitude = 90;
    bottomRightCoord.longitude = -180;
    
    if (!testing) {
        
    
    for(VenueAnnotation* annotation in mapView.annotations)
    {
        testing=YES;
        topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
        topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);
        
        bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
        bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
    }
    }
    
    MKCoordinateRegion region;
    region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
    region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
    region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1; // Add a little extra space on the sides
    region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides
    
    region = [mapView regionThatFits:region];
    [self.mapView setRegion:region animated:YES];
}

Thursday 5 July 2012

Remove Null Value From array and add real from from array...

If one array where we fetching data from database for some 
specific value,and hence the key where that particular value is not 
there,it is fetching null value in the array. 
 
 Then for removing these values just use bellow code...
 
NSMutableArray *array = [[NSMutableArray alloc]init];
array = [InteName retain];
NSLog(@"Array : : %@",array);
NSMutableArray *array1 = [[NSMutableArray alloc]init];
NSString *str;
for(int i=0;i<[array count];i++)
{
    str = [array objectAtIndex:i];
    if(str !=[NSNull null])
    {
        [array1 addObject:str]; 
        //[array removeObjectAtIndex:i];
    }
}