Mapview passing latitude,longitude problem

Discussion in 'iOS Programming' started by qqlee2000, Mar 28, 2011.

  1. qqlee2000, Mar 28, 2011
    Last edited by a moderator: Mar 28, 2011

    qqlee2000 macrumors newbie

    Joined:
    Mar 28, 2011
    #1
    I am new of xcode, I am writing about a MAPVIEW, which shown the shop location and the user current location.
    However I find out that I have to do a 20 shops list , each shop have 1 mapVIEW. I have a problem that then I have to add 20 .h &.m and 20 XIB to finish the 20 shops list.
    I don't know whether I can pass the Parameter (p1.latitude=22.327202; p1.longitude = 114.163474;) to the LocationManager function, so I don't have to repeat it 20 times.

    Please help. Thanks all

    Code:
     - (void)locationManager:(CLLocationManager *)manager
    	didUpdateToLocation:(CLLocation *)newLocation
    		   fromLocation:(CLLocation *)oldLocation {
    	
    	
    	loc = [newLocation coordinate];
    	
    	// CLLocationCoordinate2D p1;
    	
     MKCoordinateSpan span;
    	span.latitudeDelta = 0.008;
     span.longitudeDelta = 0.008;	
    	
    	
    	
    	//region.span = span;
    	//region.center = loc;
    	//region.center = loc;
    	
    	
    	p1.latitude=22.327202;
    	p1.longitude = 114.163474;
    	
    	MKCoordinateRegion region = MKCoordinateRegionMake(p1, span);
    	[map setRegion:region animated:YES];
    	[map regionThatFits:region];
    	
    	poi= [[POI alloc] initWithCoordinate:loc];
    	poi1=[[POI alloc] initWithCoordinate:p1];
    	
    	
    	poi1.title=@"大南街173號";
    	poi1.subtitle=@"聯昌皮號";
    	
    	[map addAnnotation:poi1];
    	
    
    	[poi1 release];
    	
    	
    	poi.title=@"CURRENT LOCATION";	
    	
    	[map addAnnotation:poi];
    	
    	map.showsUserLocation=YES;
    	[poi release];
    }
    
    
    
    - (void)locationManager:(CLLocationManager *)manager
    	didUpdateToLocation:(CLLocation *)newLocation
    		   fromLocation:(CLLocation *)oldLocation {
    	
    	
    	loc = [newLocation coordinate];
    	
    	// CLLocationCoordinate2D p1;
    	
     MKCoordinateSpan span;
    	span.latitudeDelta = 0.008;
     span.longitudeDelta = 0.008;	
    	
    	
    	
    	//region.span = span;
    	//region.center = loc;
    	//region.center = loc;
    	
    	
    	p1.latitude=22.327202;
    	p1.longitude = 114.163474;
    	
    	MKCoordinateRegion region = MKCoordinateRegionMake(p1, span);
    	[map setRegion:region animated:YES];
    	[map regionThatFits:region];
    	
    	poi= [[POI alloc] initWithCoordinate:loc];
    	poi1=[[POI alloc] initWithCoordinate:p1];
    	
    	
    	poi1.title=@"SHOP NO 173";
    	
    	
    	[map addAnnotation:poi1];
    	
    
    	[poi1 release];
    	
    	
    	poi.title=@"CURRENT LOCATION";
    	
    	
    	
    	[map addAnnotation:poi];
    	
    	map.showsUserLocation=YES;
    	[poi release];
    }
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    You shouldn't need to create your MapView 20 times over in order to solve this problem. You just need to make your MapView flexible enough that it can handle the store location in a variable way rather than a static one. One way to do this would be to store the coordinates in something like NSUserDefaults and then looking them up from there when you need them.

    Also, you probably don't want to be adding the annotation for your store as part of your locationManager:didUpdateToLocation:fromLocation: method, since it could be called multiple times as the user's location changes (or becomes more accurate). You only need to call it once per MapView (based on what you've described).
     
  3. qqlee2000 thread starter macrumors newbie

    Joined:
    Mar 28, 2011
    #3
    Thanks for help ! thank you very much. If you have time , Would you pls give me some more hints ? I am still searching , becuase not have much experience in programming and need more practices. Thanks
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    If you don't have much programming experience, I would suggest you step away from the real coding and make sure you are comfortable with the fundamentals of iPhone / Objective-C development. What resources have you been using so far?
     

Share This Page