Share on Google+Share on Google+

Ravi Vora
0 Answer(s)      4 years and 11 months ago
Posted in : XML
.h file

    #import <MapKit/MapKit.h>

    #define METERS_PER_MILE 1609.344

    @interface mymapViewController : UIViewController <MKMapViewDelegate,MKAnnotation,CLLocationManagerDelegate> {

        CLLocationManager *locationManager;
        IBOutlet MKMapView *map;

.m file

- (void)viewDidLoad {
    [super viewDidLoad];

        //CLLocationCoordinate2D zoomLocation;
    //    zoomLocation.latitude = 23.0000;
    //    zoomLocation.longitude = 72.4000;
    //    // 2
    //    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 500000, 500000);
    //    // 3
    //    MKCoordinateRegion adjustedRegion = [map regionThatFits:viewRegion];                
    //    // 4
    //    [map setRegion:adjustedRegion animated:YES];

        map.showsUserLocation = YES;

        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.distanceFilter = kCLDistanceFilterNone; 
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
        [locationManager startUpdatingLocation];

        //float a = 23.000;
    //  float b = 73.000;

        NSMutableArray * arr = [[NSMutableArray alloc]init];
        [arr addObject:@"23.000"];
        [arr addObject:@"73.000"];
        [arr addObject:@"73.000"];
        [arr addObject:@"23.000"];

        CLLocationCoordinate2D coordinate;
        coordinate.latitude = locationManager.location.coordinate.latitude;
        coordinate.longitude = locationManager.location.coordinate.longitude;      
        MyLocation *annotation = [[[MyLocation alloc] initWithName:@"current" address:@"sas" coordinate:coordinate] autorelease];
        [map addAnnotation:annotation]; 

        for (int i = 0 ; i < 2; i++) {
            CLLocationCoordinate2D coordinate1;
            coordinate1.latitude = [[arr objectAtIndex:i] floatValue];
            coordinate1.longitude = [[arr objectAtIndex:i+1] floatValue];
            MyLocation *annotation1 = [[[MyLocation alloc] initWithName:@"hello" address:@"sas1" coordinate:coordinate1] autorelease];
            [map addAnnotation:annotation1];

        MKCoordinateRegion region;
        MKCoordinateSpan span;
        region.span=span;, coordinate.longitude);
        [map setRegion:region animated:TRUE];


    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
        static NSString *identifier = @"MyLocation";   
        if ([annotation isKindOfClass:[MyLocation class]]) {
            MyLocation *location = (MyLocation *) annotation;

            MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier:identifier];
            if (annotationView == nil) {
                annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            } else {
                annotationView.annotation = annotation;

        annotationView.enabled = YES;
        annotationView.canShowCallout = YES;

            //if ([ compare:@"hello"] == NSOrderedSame) {
    //            annotationView.pinColor = MKPinAnnotationColorGreen;
    //      }else {
    //          annotationView.pinColor = MKPinAnnotationColorPurple;
    //      }

            return annotationView;
        return nil;


                    #import <MapKit/MapKit.h>

                    @interface MyLocation : NSObject <MKAnnotation> {
                        NSString *_name;
                        NSString *_address;
                        CLLocationCoordinate2D _coordinate;

                    @property (copy) NSString *name;
                    @property (copy) NSString *address;
                    @property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

                    - (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate;


            @synthesize name = _name;
            @synthesize address = _address;
            @synthesize coordinate = _coordinate;

            - (id)initWithName:(NSString*)name address:(NSString*)address coordinate:(CLLocationCoordinate2D)coordinate {
            if ((self = [super init])) {
                _name = [name copy];
                _address = [address copy];
                    _coordinate = coordinate;
                return self;

        - (NSString *)title {
            return _name;

        - (NSString *)subtitle {
            return _address;

        - (void)dealloc

        [_name release];
        _name = nil;
        [_address release];
        _address = nil;    
        [super dealloc];



View Answers

Related Tutorials/Questions & Answers:
mapview1  .h file #import <MapKit/MapKit.h> #define METERS_PER_MILE 1609.344 @interface mymapViewController : UIViewController <MKMapViewDelegate,MKAnnotation,CLLocationManagerDelegate>
; { IBOutlet MKMapView *mapview1; int No_of_Lat; NSMutableArray... viewWillAppear:animated]; [mapview1 setMapType:MKMapTypeStandard]; [mapview1 setZoomEnabled:YES]; [mapview1 setScrollEnabled:YES
Java Spring Hibernate Struts Training were to start with xml, XSD and java write a program that Implement an integrated COM client server to add two visuall studio 2010 Building a Parent Child relationship XML how i connect two page xml question struts cfg file for DispatchAction with mysql db Creating custom output using XMLUnit - MatchTracker duplicates the output data Related to XML Related to XML Reading child of child nodes in xml Reading multiple xml files Spliting Large XML and one by one Moved to Output Folder XMl and Java web services project download xml file from website using java code Download how to create an xml file in following clear format Conditional increment in xslt Conditional increment in xslt Conditional increment in xslt HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP? xml and servlets xml and servlets Question about parsing XML document with DOM in JAVA. Removal of XML header Converting PHP page with flash to JSP page without flash saving data in xml Doubt about Xstream Converter Reading xml file using dom parser in java with out using getelementby tag name xml dynamically how to change attiribute values in xml XML Schema xml xml sax parser for xml parsing xml using sax xml to html via java i want java code for this xml file...please show me.. SAX Parser for huge XML file xml parsing "opening video data error" in j2me XML to JSP mapview1 mapview searchbar searchbar jsonparsing xmlparsing retrieve multiple attribute values retrieve multiple attribute values


Advertisement null