
#import <CoreLocation/CoreLocation.h>
#import<CoreLocation/CLLocationManagerDelegate.h>
CLLocationManager *locationManager;
//=======
Reachability *reachability;
Reachability* internetReachable;
Reachability* hostReachable;
Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
flagreach = 0;
if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
{
UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"This app require an internet connection via WiFi or cellular network to work." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[myAlert show];
flagreach = 1;
}
if (flagreach==0)
{
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 1000.0f;
[locationManager startUpdatingLocation];
}
else {
UIAlertView *myAlert = [[[UIAlertView alloc] initWithTitle:@"No Internet Connection" message:@"This app require an internet connection via WiFi or cellular network to work." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil] autorelease];
[myAlert show];
[myAlert release];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
curr_lat=newLocation.coordinate.latitude;
curr_long=newLocation.coordinate.longitude;
}
mapview
.h file
#import <MapKit/MapKit.h>
#import "map.h"
@interface MapGraph : UIViewController<MKMapViewDelegate> {
IBOutlet MKMapView *mapview1;
int No_of_Lat;
NSMutableArray *Arr_Latitude;
NSMutableArray *Arr_Longitude;
NSMutableArray *Arr_TITLE;
NSMutableArray *Arr_SUBTITLE;
int k;
UIView *popup_view;
UIButton* rightButton;
int l;
AppDelegate_iPad *appDel;
}
@property(nonatomic,retain)NSMutableArray *Arr_Latitude;
@property(nonatomic,retain)NSMutableArray *Arr_Longitude;
@property(nonatomic,retain)NSMutableArray *Arr_TITLE;
@property(nonatomic,retain)NSMutableArray *Arr_SUBTITLE;
@property(nonatomic,readwrite)int No_of_Lat;
-(IBAction)back_to_SearchView:(id)sender;
-(IBAction)showDetails:(id)sender;
.m file
appDel=(AppDelegate_iPad *)[[UIApplication sharedApplication]delegate];
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[mapview1 setMapType:MKMapTypeStandard];
[mapview1 setZoomEnabled:YES];
[mapview1 setScrollEnabled:YES];
if (No_of_Lat==1)
{
NSLog(@"1");
MKCoordinateRegion region0 = { {0.0, 0.0 }, { 0.0, 0.0 } };
region0.center.latitude = [[Arr_Latitude objectAtIndex:0]floatValue];
region0.center.longitude = [[Arr_Longitude objectAtIndex:0]floatValue];
region0.span.longitudeDelta = 5.01f;
region0.span.latitudeDelta = 5.01f;
[mapview1 setRegion:region0 animated:YES];
[mapview1 setDelegate:self];
map *ann0 = [[map alloc] init];
NSString *str00=[Arr_TITLE objectAtIndex:0];
ann0.title = str00;
NSString *str01=[NSString stringWithFormat:@"%@",[Arr_SUBTITLE objectAtIndex:0]];
ann0.subtitle = str01;
ann0.coordinate = region0.center;
[mapview1 addAnnotation:ann0];
}
if (No_of_Lat==2)
{
NSLog(@"2");
MKCoordinateRegion region0 = { {0.0, 0.0 }, { 0.0, 0.0 } };
region0.center.latitude = [[Arr_Latitude objectAtIndex:0]floatValue];
region0.center.longitude = [[Arr_Longitude objectAtIndex:0]floatValue];
region0.span.longitudeDelta = 5.01f;
region0.span.latitudeDelta = 5.01f;
[mapview1 setRegion:region0 animated:YES];
[mapview1 setDelegate:self];
map *ann0 = [[map alloc] init];
NSString *str00=[Arr_TITLE objectAtIndex:0];
ann0.title = str00;
NSString *str01=[NSString stringWithFormat:@"%@",[Arr_SUBTITLE objectAtIndex:0]];
ann0.subtitle = str01;
ann0.coordinate = region0.center;
[mapview1 addAnnotation:ann0];
MKCoordinateRegion region1 = { {0.0, 0.0 }, { 0.0, 0.0 } };
region1.center.latitude = [[Arr_Latitude objectAtIndex:1]floatValue];
region1.center.longitude = [[Arr_Longitude objectAtIndex:1]floatValue];
region1.span.longitudeDelta = 0.01f;
region1.span.latitudeDelta = 0.01f;
[mapview1 setRegion:region1 animated:YES];
map *ann1 = [[map alloc] init];
NSString *str10=[Arr_TITLE objectAtIndex:1];
ann1.title = str10;
NSString *str11=[NSString stringWithFormat:@"%@",[Arr_SUBTITLE objectAtIndex:1]];
ann1.subtitle=str11;
ann1.coordinate = region1.center;
[mapview1 addAnnotation:ann1];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorPurple;
rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
rightButton.tag=k;
l=rightButton.tag;
k++;
//[rightButton addTarget:self
// action:@selector(showDetails:)
// forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
CGPoint origin1 = rightButton.frame.origin;
NSLog(@"Current position of right button: (%f, %f)", origin1.x, origin1.y);
//UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
//pinView.leftCalloutAccessoryView = profileIconView;
//[profileIconView release];
return pinView;
}
- (void)mapView:(MKMapView *)mapview annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[mapview deselectAnnotation:view.annotation animated:YES];
NSLog(@"latitude----%f",view.annotation.coordinate.latitude);
//NSLog(@"latitude----%d",view.annotation.subtitle);
appDel.str_title=view.annotation.title;
//NSMutableArray *Arr_sub=[[NSMutableArray alloc]init];
appDel.str_subtitle=view.annotation.subtitle;
//[Arr_sub addObject:view.annotation.subtitle];
//NSLog(@"Arr_sub----%@",Arr_sub);
appDel.Latitude=view.annotation.coordinate.latitude;
appDel.Longitude=view.annotation.coordinate.longitude;
Popup *obj_Popup = [[Popup alloc]initWithNibName:@"Popup" bundle:[NSBundle mainBundle]];
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:obj_Popup];
// self.annotationPopoverController = popOver;
popOver.popoverContentSize = CGSizeMake(400,400);
[popOver presentPopoverFromRect:view.bounds inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
map.h
#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
@interface map : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic, assign) CLLocationCoordinate2
D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end
map.m
@synthesize coordinate,title,subtitle;
-(void)dealloc
{
[title release];
[super dealloc];
}
@end
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.