0

I am using map functionality in my iphone app. I m showing stores for users current location on map. Whenever user scrolls the map he needs to be shown stores of new location. eg. suppose user at
New York at first app will show New York stores but when he scrolls map to Texas then app should fire web service request for Texas location. My problem is

1) if web service request goes at each map scroll, app may crash or wait each time for response for new set of stores. (for this i m going to put some hardcoded radius to send request) So how to handle it proper way. 2) I want to know distance between two location so that i can send request to server only if the distance between 2 locations is greater than some specific value.

I am using map view delegates for above functionality. Please suggest me some proper way to handle it.

Thanks

Swapnil
  • 1,858
  • 2
  • 22
  • 49

1 Answers1

0

Well to find the distance between 2 points i use

CLLocation *location1 = [[CLLocation alloc]initWithLatitude:[[dict valueForKey:@"lat"] doubleValue] longitude:[[dict valueForKey:@"lon"]doubleValue]]; 
float distance =[mUserCurrentLocation distanceFromLocation:location1]/1000;     
float distanceinMeters=[mUserCurrentLocation distanceFromLocation:location1];       NSString *distancestr= [NSString stringWithFormat:@"%.2f KM",distance];

See If this can help you.

Sabby
  • 2,586
  • 2
  • 27
  • 41
  • Using above i can get difference..but how to handle web service request which will get call each time on scroll? – Swapnil Oct 10 '11 at 07:02
  • if you have 2 points lat long..then calculate the distance with the above function and put some condition say for if(distance>100) then do whatever you want to do....that is i can help you with..... – Sabby Oct 10 '11 at 09:50