Wednesday, August 18, 2010

multiple annotation map

- (void)viewDidLoad
{
NSLog(@"ddddddd");
/*
locationManager=[[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate=self;
//Start the compass updates.
[locationManager startUpdatingHeading];
[[self locationManager] startUpdatingHeading];
[[self locationManager] startUpdatingLocation];
*/

[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 1.30;//41.902245099708516;
region.center.longitude = 103.8;//12.457906007766724;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];

[mapView setDelegate:self];

MyAnnotation *ann = [[MyAnnotation alloc] init];
ann.title = @"Rome";
ann.subtitle = @"San Peter";
ann.coordinate = region.center;
//[mapView addAnnotation:ann];






/// one more annt
//My own Annotation
MKCoordinateRegion SecondRegion;
SecondRegion.center.latitude = 1.301;
SecondRegion.center.longitude = 103.81;

MyAnnotation *aSecondAnnotation = [[MyAnnotation alloc] init];
aSecondAnnotation.title = @"Second Annotation";

//By the way, this line doesn’t work, everything is still in the same line :(
aSecondAnnotation.subtitle = @"clerqkey";
aSecondAnnotation.coordinate = SecondRegion.center;

//// 2 more

MKCoordinateRegion SecondRegiona;
SecondRegiona.center.latitude = 1.31;
SecondRegiona.center.longitude = 103.9;

MyAnnotation *aSecondAnnotationa = [[MyAnnotation alloc] init];
aSecondAnnotationa.title = @"3rd Annotation";

//By the way, this line doesn’t work, everything is still in the same line :(
aSecondAnnotationa.subtitle = @"ret";
aSecondAnnotationa.coordinate = SecondRegiona.center;


//////////////////////////////////////////////////////////////////////////////////////////////

NSArray *Annotations = [NSArray arrayWithObjects:ann,aSecondAnnotation,aSecondAnnotationa,nil];

[mapView addAnnotations:Annotations];


[super viewDidLoad];
}/*
- (void)locationManager:(CLLocationManager *) manager didUpdateHeading:(CLHeading *) newHeading {
NSLog(@"55555555555555555555555");
NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
NSLog(@"New true heading: %f", newHeading.trueHeading);





}
*/


- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
for (id currentAnnotation in mapView.annotations) {
[mapView selectAnnotation:currentAnnotation animated:YES];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation
{
MKPinAnnotationView *pinView = nil;
[[self locationManager] startUpdatingHeading];
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil )
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

pinView.pinColor = MKPinAnnotationColorPurple;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
}
else
{
[mapView.userLocation setTitle:@"I am here"];
}

return pinView;
}

Thursday, August 12, 2010

unzip data from web

NSString *aDirectory =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];


NSFileManager *fileManager= [NSFileManager defaultManager];

NSString* filePath = [NSString stringWithFormat:@"%@/temp.zip", aDirectory];
NSString* updateURL = @"http://localhost/list.zip";
NSLog(@"Checking update at : %@", updateURL);
NSData* updateData = [NSData dataWithContentsOfURL: [NSURL URLWithString: updateURL] ];

[fileManager createFileAtPath:filePath contents:updateData attributes:nil];

ZipArchive *zipArchive = [[ZipArchive alloc] init];

if([zipArchive UnzipOpenFile:filePath]) {

if ([zipArchive UnzipFileTo:aDirectory overWrite:YES]) {
//unzipped successfully
NSLog(@"Archive unzip Success");
[fileManager removeItemAtPath:filePath error:NULL];
} else {
NSLog(@"Failure To Unzip Archive");
}

} else {
NSLog(@"Failure To Open Archive");
}

[zipArchive release];

NSLog(@"string text is %@",filePath);

Tuesday, August 10, 2010

saving locaaly and update data from web

#pragma mark save file locally


NSString *applicationDocumentsDir =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *storePath = [applicationDocumentsDir stringByAppendingPathComponent:@"sample1.cfg"];

NSURL *instructionsURLd = [[NSURL alloc] initFileURLWithPath:filePath];
NSData *dataXML = [NSData dataWithContentsOfURL:instructionsURLd];

[dataXML writeToFile:storePath atomically:YES];

// NSLog(@"matrix path %@",applicationDocumentsDir);
//NSLog(@"neo path %@",storePath);



#pragma mark update
// http://localhost/update.cfg

//NSData *dataXML = [NSData dataWithContentsOfURL:instructionsURLd];

NSURL *urlf = [[NSURL alloc] initWithString:@"http://localhost/update.cfg"];
dataXML = [NSData dataWithContentsOfURL:urlf];


NSMutableData *file = [[NSMutableData alloc] initWithContentsOfFile:storePath];
[file appendData:dataXML];
[file writeToFile:storePath atomically:YES];

Friday, August 6, 2010

Dynamic buttons and method on them

#pragma mark load filePath
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"tabs" ofType:@"cfg"];
if (filePath) {


NSString *myText = [NSString stringWithContentsOfFile:filePath];

NSMutableArray *a1 = [[NSMutableArray alloc] init];
[a1 addObjectsFromArray:[myText componentsSeparatedByString:@"\n"]];

[a1 addObject:myText];


NSUInteger i;
for (i = 1; i <= [a1 count]-1; i++)
{

NSString *urlE=[a1 objectAtIndex:1];
NSLog(@"url is %@",urlE);




#pragma mark buttons
CGRect frame = CGRectMake(curXLoc, 10, 60, 30);
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = frame;
button.tag=i;
[button setImage:[UIImage imageNamed:@"tab2.png"] forState:UIControlStateNormal];
[button setTitle:(NSString *)@"new button" forState:(UIControlState)UIControlStateNormal];
[button addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
curXLoc += (kScrollObjWidth1);
[self.view addSubview:button];


}




}
}





-(void)buttonEvent:(UIButton*)sender{
NSLog(@"new button clicked!!!");
if (sender.tag == 1) {
NSLog(@"1");
}
if (sender.tag == 2) {
NSLog(@"2");
}
}

FEEDJIT Live