ios - MKMapView how to change the User Nearest location pin image? -


i want change user nearest location pin image in map view.

"in project show of shop locations in map view. locations (lat,long) api. here changed given location pin image. works fine. need change user nearest location pin image in map view. distance details user current location given api locations in locations below 5 miles location pin images need change. "

here annotation code:

// view annotation delegate code changing pin image.

     -(mkannotationview *)mapview:(mkmapview *)mapview viewforannotation: (id<mkannotation>)annotation     {  [self.annotationcustom_view removefromsuperview]; [self.annotationcurrentloc_view removefromsuperview];  static nsstring *identifier = @"myannotation"; custommapviewannotation * annotationview = (custommapviewannotation *)[self.locationsmap_view dequeuereusableannotationviewwithidentifier:identifier]; if (!annotationview) {     annotationview = [[custommapviewannotation alloc] initwithannotation:annotation reuseidentifier:identifier];      if([annotation iskindofclass:[mkuserlocation class]])     {         annotationview.image = [uiimage imagenamed:@"locationsyour-current-location-icon"];    // user current location image     }     else     { dispatch_async(dispatch_get_main_queue(), ^{           for(int i=0;i<[locations_arraylist count];i++)         {                 mapviewlocationmodel *objvalue=[locations_arraylist objectatindex:i];              float value = [objvalue.kiosk_distance floatvalue];                 if(value < 5.0)                 {                  annotationview.image = [uiimage imagenamed:@"locationsfridge-location-icon"];    // change pin image below 5.0 miles distance user current locations                  }                 else                 {                     annotationview.image = [uiimage imagenamed:@"locationsblackdot"];     // given api locations pin images                 }         }       });         } }  annotationview.canshowcallout = no;  return annotationview;      } 

this code. 1 can me on this?

try following:

in order display pins in map area, first need pins inside 5 miles.

 // 1. set map zoom area visible of 5 miles:         mapview.region = mkcoordinateregionmakewithdistance(             centercoordinate,              1609.344f * miles (5 in case),             1609.344f * miles (5 in case)         );     //  2. rect of map area:          mkmaprect mrect = self.map.visiblemaprect;     //  3. pins inside rect:          nsset *annotationset = [mymapview annotationsinmaprect:mrect];          // print number of annotations         nslog(@"number of annotations in rect: %d", annotationset.count);          // return array nsset         nsarray *annotationarray = [annotationset allobjects];      //  4. assign parameter annotation, taking property in annotation class.     //  5. in mapview delegate method viewforannotation check parameter , need full respective pins. 

hope achieve want.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -