locationmanager - iOS didEnterRegion never called -
i have problems ios , gefencing...
// // viewcontroller.m // // // created me on 14.05.13. // copyright (c) 2013 me. rights reserved. // #import "viewcontroller.h" @interface viewcontroller ()<cllocationmanagerdelegate> { cllocationmanager *locationmanager; clregion *testregion; } #define meters_per_mile 1609.344 @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; [self initlocationmanager]; // [self startlocationmanager]; } // init location manager object, set delegation, result , accurate - (void)initlocationmanager { //create location manager object locationmanager = [[cllocationmanager alloc]init]; //this instance send messages our appdelegate [locationmanager setdelegate:self]; //to results location manager [locationmanager setdistancefilter:kcldistancefilternone]; //be accurate possible [locationmanager setdesiredaccuracy:kcllocationaccuracybest]; } - (void)viewwillappear:(bool)animated { cllocationcoordinate2d startlocation; startlocation.latitude = +52.53753000; startlocation.longitude= +13.35971000; mkpointannotation *newlocation = [[mkpointannotation alloc] init]; newlocation.coordinate = startlocation; newlocation.title = @"great title"; newlocation.subtitle = @"great subtitle"; mkcoordinateregion startingregion = mkcoordinateregionmakewithdistance(startlocation, 0.5*meters_per_mile, 0.5*meters_per_mile); testregion = [[clregion alloc] initcircularregionwithcenter:startlocation radius:500 identifier:@"test"]; [_mapview addannotation:newlocation]; [_mapview setregion:startingregion animated:yes]; [locationmanager startmonitoringforregion:testregion]; nslog(@"%@",locationmanager.monitoredregions); } - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error { nslog(@"error : %@",error); } - (void)locationmanager:(cllocationmanager *)manager monitoringdidfailforregion:(clregion *)region witherror:(nserror *)error { nslog(@"region monitoring failed error: %@", [error localizeddescription]); } - (void)locationmanager:(cllocationmanager *)manager didenterregion:(clregion *)region { nslog(@"entered region - %@", region.identifier); // [self showregionalert:@"entering region" forregion:testregion.identifier]; } - (void)locationmanager:(cllocationmanager *)manager didstartmonitoringforregion:(clregion *)region { nslog(@"started monitoring %@ region", region.identifier); } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } @end
the terminal give me following messages:
2013-05-15 00:24:47.739 [8712:13d03] {( (identifier test) <+52.53753000,+13.35972000> radius 500.00m )} 2013-05-15 00:24:47.972 [8712:13d03] started monitoring test region
so region created , monitoring start thedidenterregion
function never called.
help great!
edit:
at moment i'm using gpx file in iphone simulator , works fine. didenterregion
never called.
<?xml version="1.0" encoding="utf-8" standalone="no" ?> <gpx version="1.1" creator="http://www.geoplaner.com" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://www.topografix.com/gpx/1/1" xsi:schemalocation="http://www.topografix.com/gpx/1/1 http://www.topografix.com/gpx/1/1/gpx.xsd"> <wpt lat="52.53856" lon="13.3515"> <ele>36.6</ele> <name>wp04-d</name> </wpt> <wpt lat="52.53753" lon="13.35972"> <ele>35.1</ele> <name>wp05-e</name> </wpt> <wpt lat="52.538" lon="13.35788"> <ele>34.1</ele> <name>wp06-f</name> </wpt> <wpt lat="52.53844" lon="13.35633"> <ele>33.6</ele> <name>wp07-g</name> </wpt> <wpt lat="52.53895" lon="13.35392"> <ele>34.7</ele> <name>wp08-h</name> </wpt> <wpt lat="52.53813" lon="13.34925"> <ele>36</ele> <name>wp09-i</name> </wpt> <wpt lat="52.53794" lon="13.34667"> <ele>36.3</ele> <name>wp10-j</name> </wpt> <wpt lat="52.53815" lon="13.34504"> <ele>37.1</ele> <name>wp11-k</name> </wpt> <wpt lat="52.5369" lon="13.35938"> <ele>39.3</ele> <name>wp12-l</name> </wpt> <wpt lat="52.53619" lon="13.35792"> <ele>33.3</ele> <name>wp13-m</name> </wpt> <wpt lat="52.53468" lon="13.35508"> <ele>37.3</ele> <name>wp14-n</name> </wpt> <wpt lat="52.53398" lon="13.35367"> <ele>37</ele> <name>wp15-o</name> </wpt> <wpt lat="52.53781" lon="13.35862"> <ele>33.7</ele> <name>wp16-p</name> </wpt> </gpx>
your code looks fine. ensure locationmanager retained/strongly-held.
test region code using iphone simulator. on 'debug' menu chose location 'location' submenu. changing different locations exercise code.
i tested code using iphone simulator , choosing locations submenu. entered code's lat/long numbers 'custom location'. here output:
2013-05-15 07:42:50.885 location[69277:c07] {( (identifier home) <+37.26917400,-119.30660700> radius 100.00m )} 2013-05-15 07:42:50.932 location[69277:c07] started monitoring test region 2013-05-15 07:44:01.103 location[69277:c07] entered region - test 2013-05-15 07:44:59.573 location[69277:c07] entered region - test
the 'entered region' output occurred when chose 'custom location'. changes made code were: 1) commented out 'mapview' lines , 2) declared viewcontroller interface shown below. had used class extension.
@interface viewcontroller : uiviewcontroller <cllocationmanagerdelegate> { cllocationmanager *locationmanager; clregion *testregion; } @end
ensure location services enabled app.
Comments
Post a Comment