Search code examples
iphoneobjective-cmkmapviewmkmapviewdelegate

Map view refresh in iPhone app


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


Solution

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