Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Ravi Vora
mapview
0 Answer(s)      a year and 11 months ago
Posted in : XML


#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

Advertisement
View Answers

Related Tutorials/Questions & Answers:
mapview
; } mapview .h file #import <MapKit/MapKit.h> #import "map.h...]; } - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>
MapView Example in iPhone
MapView Example in iPhone The example illustrate how to embed or display a MapView in iPhone SDK UIView based application. To embed a Map in your iphone... on UIView. It should look like the given image. Download code of MapView Example
Advertisements
iPhone MapView Current Location
iPhone MapView Current Location This is a simple MKMapView example in iPhone... mapviewViewController : UIViewController { IBOutlet MKMapView *mapview; } @property(nonatomic, retain) IBOutlet MKMapView *mapview; @end and in the .m
MKMapView Change Red Pin Color
the problem. or See the code below... - (void)mapView:(MKMapView *)mapView... a annotation(my assumption) [mapView addAnnotation:yourAnnotation]; //This will call viewForAnnotation again } - (MKAnnotationView *)mapView:(MKMapView
How to add UIImage on pin location MKMapKit
How to add UIImage on pin location MKMapKit  Hi, In my application, i need to add a custom image on MapView controller instead of pin. I am calling image through database "URL". Please suggest .. Thanks!   
how to do map in iphone?-RV
; IBOutlet MKMapView *mapView; NSMutableArray *arr; NSMutableArray *arr... MKMapView *mapView; @end In mapkitdisplayviewcontroller.m #import... mapView; - (void)viewDidLoad { [super viewDidLoad]; g=0; arr
File I/O
lifecycle management Setup and teardown of services behind a MapView Creating... and teardown of services behind a MapView Creating Finally, its time to write... of services behind a MapView Creating Finally, its time to write some code. Bookmark
mapview1
animated:TRUE]; } - (MKAnnotationView *)mapView:(MKMapView *)mapView
Advertisements
 

 

 

DMCA.com