ios - Show MapView Annotations for Selected Radius -


i have map view several annotations on it. have settings button on navigation bar takes user picker view lets them show annotations or select radius of 5, 10, 25, 50, or 100 miles current location see annotations selected radius. i'm not sure how go having map show annotations selected radius. can @ least point me in right direction?

here map:

#import "rsfm.h" #import "annotationdetailview.h" #import "mapsettings.h"  @interface rsfm ()  @end  @implementation rsfm {  }  @synthesize centercoordinate, coordinate, title, subtitle, marketannotation, location;  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil {     self = [super initwithnibname:nibnameornil bundle:nibbundleornil];      if (self)     {         self.title = nslocalizedstring(@"farm markets", @"farm markets");         // create location manager object         locationmanager = [[cllocationmanager alloc]init];          [locationmanager setdelegate:self];          // , want accurate possible regardless of how time/power takes         [locationmanager setdesiredaccuracy:kcllocationaccuracythreekilometers];          // tell our manager start looking location         // [locationmanager startupdatinglocation];     }      return self; } /* - (void)setcentercoordinate:(cllocationcoordinate2d)centercoordinate {     centercoordinate = cllocationcoordinate2dmake(37.7885, 85.3279); } */ - (void)findlocation {     [locationmanager startupdatinglocation];     [activityindicator startanimating];     // [locationtitlefield sethidden:yes];     [locationmanager stopupdatinglocation]; }  - (void)foundlocation:(cllocation *)loc {     cllocationcoordinate2d coord = [loc coordinate];      // zoom region location     mkcoordinateregion region = mkcoordinateregionmakewithdistance(coord, 400000, 400000);     [worldview setregion:region animated:yes];      // reset ui     // [locationtitlefield settext:@""];     [activityindicator stopanimating];     // [locationtitlefield sethidden:no];     [locationmanager stopupdatinglocation]; }  - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation {     nslog(@"%@", newlocation);      // how many seconds ago new location created?     nstimeinterval t = [[newlocation timestamp]timeintervalsincenow];      // cllocationmanagers return last found location of device first, don't want data in case.     // if location made more 3 minutes ago, ignore it.     if (t < -180)     {         // cached data, don't want it, keep looking         return;     }      [self foundlocation:newlocation]; }  - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error {     nslog(@"could not find location: %@", error); }  - (void)dealloc {     // tell location manager stop sending messages     [locationmanager setdelegate:nil]; }  - (mkannotationview*)mapview:(mkmapview *)mapview viewforannotation:(id<mkannotation>)annotation {     // if it's user location, return nil     if ([annotation iskindofclass:[mkuserlocation class]])         return nil;      // try dequeue existing pin view first     static nsstring *annotationidentifier = @"annotationidentifier";     mkpinannotationview *pinview = [[mkpinannotationview alloc]initwithannotation:annotation reuseidentifier:annotationidentifier];     pinview.animatesdrop = no;     pinview.pincolor = mkpinannotationcolorred;     pinview.canshowcallout = yes;      uibutton *rightbutton = [uibutton buttonwithtype:uibuttontypedetaildisclosure];     [rightbutton settitle:annotation.title forstate:uicontrolstatenormal];     pinview.rightcalloutaccessoryview = rightbutton;      return pinview; }  - (void)mapview:(mkmapview *)mapview annotationview:(mkannotationview *)view calloutaccessorycontroltapped:(uicontrol *)control {     annotationdetailview *detail = [[annotationdetailview alloc] initwithnibname:nil bundle:nil];     id<mkannotation> ann = [mapview.selectedannotations objectatindex:0];     ann = view.annotation;     cllocationcoordinate2d anncoord;     anncoord.latitude = ann.coordinate.latitude;     anncoord.longitude = ann.coordinate.longitude;     detail.modaltransitionstyle = uimodaltransitionstylefliphorizontal;     nslog(@"%@", ann.title);     nslog(@"%@", ann.subtitle);     detail.anntitle = ann.title;     detail.annsub = ann.subtitle;     detail.lattext = [nsstring localizedstringwithformat:@"%f",anncoord.latitude];     detail.longtext = [nsstring localizedstringwithformat:@"%f", anncoord.longitude];     [self.navigationcontroller pushviewcontroller:detail animated:yes]; }  - (ibaction)mapsettingsbuttonpressed:(id)sender {     mapsettings *mapsettings = [[mapsettings alloc] initwithnibname:nil bundle:nil];     [self.navigationcontroller pushviewcontroller:mapsettings animated:yes]; }  - (void)viewdidload {     [locationmanager startupdatinglocation];     [worldview setshowsuserlocation:yes];     [locationmanager stopupdatinglocation];      uibarbuttonitem *settingsbutton = [[uibarbuttonitem alloc] initwithtitle:@"\u2699" style:uibarbuttonitemstylebordered target:self action:@selector(mapsettingsbuttonpressed:)];     [settingsbutton settitletextattributes:[nsdictionary dictionarywithobjectsandkeys:[uifont boldsystemfontofsize:24], uitextattributefont,nil] forstate:uicontrolstatenormal];     self.navigationitem.rightbarbuttonitem = settingsbutton;       nsmutablearray *marketlocations = [[nsmutablearray alloc]init];      nsmutablearray *lat = [[nsmutablearray alloc]initwithobjects:@"37.7867266", @"37.0703517", @"37.1610806", @"37.318367", @"37.3559204", @"37.4154066", @"37.4757622", @"37.7450252", @"37.6318978", @"37.0716803", @"36.7333486", @"36.8637044", @"36.9181305", @"36.8736459", @"36.93253", @"37.0436832", @"37.1516087", @"36.712052", @"36.8082663", @"37.1799935", @"37.8928444", @"37.7488563", @"37.499522", @"37.5882222", @"37.4991846", @"37.5392879", @"37.3721288", @"37.1922315", @"37.102841", @"36.9813651", @"36.660251", @"37.1301316", @"37.1734765", @"37.0505279", @"36.9179492", @"37.2742692", @"37.2116415", @"37.2412938", @"37.2696374", @"37.5464147", @"37.5693561", @"37.7146149", @"37.7647463", @"37.635366", @"37.6417237", @"37.8515069", @"37.6840096", @"37.6000712", @"37.6655401", @"37.6668541", @"37.710869", @"37.7101039", @"37.8721419", @"37.9711379", @"38.0069215", @"38.135998", @"38.105713", @"38.160352", @"38.223825", @"38.188871", @"38.235703", @"38.3586935", @"38.3069755", @"38.6109009", @"38.3600355", @"38.4004693", @"38.5997367", @"38.6414842", @"38.5741722", @"38.1756649", @"38.2686626", @"38.4329612", @"38.673506", @"38.1916673", @"38.2265882", @"38.7363261", @"38.9734399", @"38.977975", @"38.8985392", @"38.903505", @"38.7418795", @"38.5102869", @"38.4260502", @"38.2687025", @"38.2097987", @"38.2074495", @"38.1356551", @"38.1245065", @"38.036634", @"37.9976315", @"37.7785109", @"37.9324058", @"37.9442351", @"37.9631701", @"37.9572905", @"38.0575357", @"37.8184352", @"37.920693", @"37.6256607", @"38.8029428", @"37.911885", @"38.4948355", @"38.5124872", @"38.359333", @"37.5453841", @"36.7641572", @"37.5846472", nil];      nsmutablearray *lon = [[nsmutablearray alloc]initwithobjects:@"-87.608209", @"-88.1237899", @"-87.9148629", @"-87.5074402", @"-87.5448032", @"-87.8003148", @"-87.9515986", @"-87.9061638", @"-87.1148574", @"-87.3008418", @"-87.5661605", @"-87.290597", @"-86.8270899", @"-86.6544847", @"-86.490067", @"-86.4558939", @"-86.2038694", @"-86.3287002", @"-85.9428197", @"-85.8312895", @"-86.2219159", @"-85.8042332", @"-85.8837926", @"-85.6896553", @"-85.6185338", @"-85.3974197", @"-85.3594512", @"-85.5906947", @"-85.3063504", @"-85.060269", @"-85.212777", @"-84.8720139", @"-84.8137247", @"-84.5698918", @"-84.1312625", @"-84.4614493", @"-84.4802606", @"-84.4223536", @"-84.6410206", @"-84.4564877", @"-84.2884479", @"-84.4089207", @"-84.3655048", @"-84.5597937", @"-84.7606165", @"-84.8732843", @"-85.2055835", @"-85.0401771", @"-85.248661", @"-85.1834814", @"-85.261238", @"-85.259706", @"-85.3155742", @"-85.689489", @"-85.8210816", @"-85.503977", @"-85.654787", @"-85.855705", @"-85.592095", @"-85.520966", @"-85.156767", @"-85.1048516", @"-85.1471807", @"-85.1186233", @"-85.5047839", @"-85.3788328", @"-85.3060421", @"-85.3237933", @"-85.2994716", @"-84.8965549", @"-84.6066196", @"-84.8581488", @"-84.8477954", @"-84.541101", @"-84.5685446", @"-84.6280011", @"-84.721179", @"-84.749313", @"-84.6090422", @"-84.441984", @"-84.0662604", @"-83.8971076", @"-83.8566679", @"-84.2433673", @"-84.2529869", @"-84.4785665", @"-84.3652534", @"-84.3541421", @"-84.551631", @"-84.7000274", @"-84.5389521", @"-84.3865064", @"-84.2261198", @"-84.2162117", @"-83.793939", @"-83.9017386", @"-84.0842092", @"-83.2513743", @"-83.5944371", @"-81.2244293", @"-82.748201", @"-82.8310584", @"-82.7304443", @"-83.5611122", @"-84.3922468", @"-86.8666113",@"-87.2933751", nil];      nsmutablearray *title1 = [[nsmutablearray alloc]initwithobjects:@"cates farm", @"broadbent b & b foods", @"cayce's pumpkin patch", @"metcalfe landscaping", @"brumfield farm market", @"dogwood valley farm", @"country fresh meats & farmers market", @"jim david meats", @"trunnell's farm market", @"lovell's orchard & farm market", @"zook's produce", @"the country barn", @"poore's nursery & farms", @"just piddlin farm", @"chaney's dairy barn & restaurant", @"jackson's orchard & nursery, inc.", @"mammoth cave transplants", @"habegger's amish market", @"kenny's farmhouse cheese", @"dennison's roadside market", @"roberts family farm", @"wooden farm", @"jordan greenhouses", @"lee's garden center, florist & gift shop", @"hinton's orchard & farm market", @"serenity farm alpacas", @"burton's nursery & garden center", @"davis family farms", @"heavenly haven farm", @"french valley farms", @"cravens greenhouse", @"haney's appledale farm", @"hettmansperger's greenhouse", @"d & f farms", @"double hart farm", @"owens garden center", @"hail's farm", @"sinking valley vineyard & winery, inc.", @"todd's greenhouse & florist, llc", @"mcquerry's family farm-herbs-n-heirlooms", @"berea college farm & gardens", @"acres of land winery & restaurant", @"baldwin farms", @"wonder of life farm", @"chateau du vieux corbeau winery/old crow farm winery", @"devine's farm & corn maze", @"flaggy meadow fiber works & sunshine alpacas of kentucky", @"williams country market", @"serano alpacas & yarns", @"1851 historic maple hill manor b & b, alpaca & llama farm, & fiber farm store", @"campbell farm wool art center", @"st. catharine farm", @"capture heart alpacas", @"ridgeview greenhouse & nursery", @"country corner greenhouse & nursery, inc", @"sunny acres farm", @"morrison's greenhouses", @"george gagel farm market, llc", @"thieneman's herbs & perennials", @"tower view farm & nursery", @"gallrein farms", @"sweet home spun in low dutch meetinghouse", @"mulberry orchard, llc", @"gregory farms", @"foxhollow farm store", @"sherwood acres beef", @"bray orchard & roadside market", @"callis orchards", @"bray fruit", @"wilson's nursery", @"triple j farm", @"ayres family orchard", @"michels family farm", @"amerson farm", @"bi-water farm & greenhouse", @"alpine hills dairy tour/country pumpkins", @"blue ribbon market", @"eagle bend alpacas fiber & gift shoppe", @"benton farms", @"redman's farm",@"the greenhouse in gertrude", @"croppers greenhouse & nursery", @"mclean's aerofresh fruit", @"julie's pumpkins", @"reed valley orchard", @"evans orchard & cider mill", @"kentucky green market", @"antioch daylily garden", @"golden apple fruit market", @"boyd orchards", @"serenity hill fiber & living history farm", @"kelley farms", @"beech springs farm market", @"yuletide tree farm & nursery", @"townsend's sorghum mill , farm market", @"bramble ridge orchard", @"c2h2 farm market", @"fannin's vegetables", @"country garden greenhouse", @"golden apple fruit market", @"black barn produce, llc", @"imel's greenhouse", @"feathered wing farm market", @"hutton-loyd tree farm", @"halcomb's knob, llc", @"martin farms", @"happy hollow farms",nil];      nsmutablearray *subtitle1 = [[nsmutablearray alloc]initwithobjects:@"hwy 425 henderson, ky 42420", @"257 mary blue road kuttawa, ky 42055", @"153 farmersville road princeton, ky 42445", @"410 princeton road madisonville, ky 42431", @"3320 nebo road madisonville, ky 42431", @"4551 state route 109n clay, ky 42404", @"9355 hwy 60 w sturgis, ky 42459",@"350 t. frank wathen rd. uniontown, ky 42461", @"9255 hwy 431 utica, ky 42376", @"22850 coal creek road hopkinsville, ky 42240", @"intersection of ky107 & ky117 herndon, ky  42240", @"112 britmart road elkton, ky 42220", @"5486 morgantown road   russellville, ky 42276", @"10830 s. morgantown rd.  woodburn, ky 42170", @"9191 nashville road, bowling green, ky 42101", @"1280 slim island road   bowling green, ky 42101", @"5394 brownsville road brownsville, ky 42210", @"945 perrytown road  scottsville, ky 42164", @"2033 thomerson park road austin, ky 42123", @"5824 s. jackson hwy. horse cave, ky 42749", @"125 kennedy road guston, ky   40142", @"1869 wooden lane elizabethtown, ky 42701", @"13287 dixie highway upton, ky 42784", @"1918 bardstown road hodgenville, ky 42748", @"8631 campbellsville road hodgenville, ky 42748", @"1380 frogg lane raywick, ky 40060", @"2212 saloma road campbellsville, ky 42718", @"313 hwy 1464 greensburg, ky 42743", @"230 heavenly lane columbia, ky 42728", @"1842 n. main st. jamestown, ky 42629", @"500 cedar hill road albany, ky 42602", @"8350 west 80 nancy, ky 42544-8756", @"3917 n. hwy 837 science hill, ky 42553", @"755 elihu rush branch road somerset, ky 42501", @"6550 cumberland falls road corbin, ky 40701", @"735 latham road somerset, ky 42503", @"hwy 461, @ 3 mile marker somerset, ky 42503", @"1300 plato-vanhook road somerset, ky 42503", @"35 skyline drive eubank, ky 42567", @"169 pine hill road paint lick, ky 40461", @"230 n. main st. berea, ky 40404", @"2285 barnes mill road richmond, ky 40475", @"1113 tates creek road richmond, ky 40475", @"686 buckeye road lancaster, ky 40444", @"471 stanford avenue danville, ky 40422-1927", @"623 talmage-mayo road harrodsburg, ky 40330", @"2110 mackville road springfield, ky 40069", @"4189 craintown rd. gravel switch, ky 40328", @"1805 booker road springfield, ky 40069", @"2941 perryville road, 150 springfield, ky 40069", @"2888 bardstown road springfield, ky 40069", @"2645 bardstown road springfield, ky 40061", @"9430 bloomfield road bloomfield, ky 40008", @"460 buffalo run road shepherdsville, ky 40165", @"4877 hwy 44e shepherdsville, ky 40165", @"6516 echo trail jeffersontown, ky 40299", @"5613 cooper chapel road louisville, ky 40229", @"2400 lower hunters trace louisville, ky 40216", @"9120 blowing tree road louisville, ky 40220", @"12523 taylorsville road jeffersontown, ky 40299", @"1029 vigo road shelbyville, ky 40065", @"6805 castle hwy. pleasureville, ky 40057", @"1330 mulberry pike shelbyville, ky 40065", @"985 vance road turners station, ky 40075", @"8905 hwy 329 crestwood, ky 40014", @"215 parker drive lagrange, ky 40031", @"2580 hwy 42 w. bedford, ky 40006", @"3721 hwy 421 n bedford, ky 40006", @"1660 highway 421 n bedford, ky 40006", @"3690 east-west connector (rte 676) frankfort, ky 40601", @"2287 long lick road georgetown, ky 40324", @"525 wilson lane owenton, ky 40359", @"4275 hwy 1316 sparta, ky 41086", @"130 mcclelland circle georgetown, ky 40324", @"877 cincinnati road georgetown, ky 40324", @"2165 sherman mount zion rd. dry ridge, ky 41035", @"8707 camp ernst road union, ky 41091", @"7812 east bend road burlington, ky 41005", @"11896 old lexington pike walton, ky 41094", @"12449 decoursey pike morning view, ky 41063", @"3246 augusta-berlin road brooksville, ky 41004", @"5350 raymond road may's lick, ky 41055", @"4085 ewing road ewing, ky 41039", @"1069 ruddles mill road paris, ky 40361", @"239 lail lane paris, ky 40361", @"180 stone road georgetown, ky 40324", @"5751 lexington rd. lexington, ky 40511", @"2231 houston antioch road lexington, ky 40516", @"1801 alexandria drive lexington, ky 40504", @"1396 pinckard pike versailles, ky 40383", @"1371 beverly lane nicholasville, ky 40356", @"6483 old richmond road lexington, ky 40515", @"4776 old boonesboro road winchester, ky 40391", @"3925 old boonesboro road winchester, ky 40391", @"11620 main street jeffersonville, ky 40337", @"2726 osborne road mt. sterling, ky 40353", @"1098 harris ferry road irvine, ky 40336", @"2140 hwy 460w west liberty, ky 41472", @"99 union road beattyville, ky 41311", @"1523 hwy 119 north whitesburg, ky 41815", @"52 ky route 3224 river, ky 41254", @"2836 state route 1 greenup, ky 41144", @"45 katherine lane greenup, ky 41144", @"1483 big run road wallingford, ky 41093", @"430 wallacetown road paint lick, ky 40461", @"5595 nashville road russellville, ky 42276", @"9730 ky 136w calhoun, ky 42327", nil];      nslog(@" lat count: %lu", (unsigned long)[lat count]);     nslog(@" long count: %lu", (unsigned long)[lon count]);     nslog(@" title count: %lu", (unsigned long)[title1 count]);     nslog(@" subtitle count: %lu", (unsigned long)[subtitle1 count]);      // cllocationcoordinate2d location;     // mkpointannotation *marketannotation;      (int x = 0; x < [lat count]; x++)     {         marketannotation = [[mkpointannotation alloc]init];         location.latitude = [[lat objectatindex:x]floatvalue];         location.longitude = [[lon objectatindex:x]floatvalue];         marketannotation.coordinate = location;         marketannotation.title = [title1 objectatindex:x];         marketannotation.subtitle = [subtitle1 objectatindex:x];         [marketlocations addobject:marketannotation];     }      [worldview addannotations:marketlocations]; }  - (void)mapview:(mkmapview *)mapview didupdateuserlocation:(mkuserlocation *)userlocation {     cllocationcoordinate2d loc = [userlocation coordinate];      mkcoordinateregion region = mkcoordinateregionmakewithdistance(loc, 400000, 400000);     [worldview setregion:region animated:yes];     [locationmanager stopupdatinglocation];     locationmanager.delegate = nil; }  - (ibaction)selectsegmentcontrol {     int segmenttouched = [mapvarieties selectedsegmentindex];     nsstring *segmentname = [mapvarieties titleforsegmentatindex:segmenttouched];     if ([segmentname isequaltostring:@"street"])     {         [worldview setmaptype:mkmaptypestandard];     }     if ([segmentname isequaltostring:@"satellite"])     {         [worldview setmaptype:mkmaptypesatellite];     }     if ([segmentname isequaltostring:@"hybrid"])     {         [worldview setmaptype:mkmaptypehybrid];     } }  @end 

and here settings view picker view:

#import "mapsettings.h"  @interface mapsettings ()  @end  @implementation mapsettings  @synthesize radiuspicker, radiusarray;  - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil {     self = [super initwithnibname:nibnameornil bundle:nibbundleornil];     if (self) {         // custom initialization         self.title = @"map settings";     }     return self; }  - (void)viewdidload {     [super viewdidload];      radiusarray = [[nsmutablearray alloc]initwithobjects:@"show all", @"5 miles", @"10 miles", @"25 miles", @"50 miles", @"100 miles", nil];      radiuspicker = [[uipickerview alloc]init];     [radiuspicker setdatasource:self];     [radiuspicker setdelegate:self];     [radiuspicker setframe:cgrectmake(88, 125, 144, 150)];     radiuspicker.showsselectionindicator = yes;     [radiuspicker selectrow:0 incomponent:0 animated:yes];     [self.view addsubview: radiuspicker]; }  -(nsinteger)numberofcomponentsinpickerview:(uipickerview *)pickerview {     return 1; }  -(nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component {     return [radiusarray count]; }  -(nsstring *)pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row forcomponent:(nsinteger)component {     return [radiusarray objectatindex: row]; }  -(void)pickerview:(uipickerview *)pickerview didselectrow:(nsinteger)row incomponent:(nsinteger)component {     nslog(@"%@", [radiusarray objectatindex: row]); }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  @end 

the cllocation class has method

- (cllocationdistance)distancefromlocation:(const cllocation *)location 

which can use calculate distances between current user's location , annotations. if it's less fx 10 km, annotation should added map, otherwise should skipped.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -