Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

qqlee2000

macrumors newbie
Original poster
Mar 28, 2011
2
0
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];
}
 
Last edited by a moderator:

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

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).
 

qqlee2000

macrumors newbie
Original poster
Mar 28, 2011
2
0
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).

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
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.