Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In my application i used to MKmapview to show the current pet position using gps device , While the pet in moving condition the postion of the pet is not refreshing in ios6.1 accesses by apple MAP, when i tried with ios5 its accessed by google map its working properly.IS it any prob with my code as follows,

 - (MKAnnotationView *) mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
if(annotation==petAnnotation)
{
    static NSString *pinID = @"mapPin";
    pinAnnotation = (MKPinAnnotationView *)[_myMapView dequeueReusableAnnotationViewWithIdentifier:pinID];
    if (pinAnnotation == nil)
        pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinID] autorelease];
    pinAnnotation.image = [UIImage imageNamed:@"blue_marker.png"];
    pinAnnotation.canShowCallout = YES;
    [pinID release];
    }
else if(annotation==currentAnnotation)
{
    static NSString *pinID = @"mapPin";
    pinAnnotation = (MKPinAnnotationView *)[_myMapView dequeueReusableAnnotationViewWithIdentifier:pinID];
    if (pinAnnotation == nil)
        pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinID] autorelease];
    // Set the image
    pinAnnotation.image = [UIImage imageNamed:@"my_loc.png"];
    // Set ability to show callout
    pinAnnotation.canShowCallout = YES;
    // Set up the disclosure button on the right side
    //UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    //pinAnnotation.rightCalloutAccessoryView = infoButton;
    [pinID release];
}
return pinAnnotation;
[pinAnnotation release];
}


-(NSArray *)getAddressFromLatLon
 {
NSLog(@"%@",latitude1);
NSLog(@"%@",longitude1);
NSString *urlString =[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%@,%@&sensor=true",latitude1,longitude1];
// NSLog(@"%@",urlString);
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSLog(@"%@",request);
NSData *response1 = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(@"%@",response1);
NSDictionary *alldicdata=[NSJSONSerialization JSONObjectWithData:response1 options:0 error:nil];
 NSLog(@"%@",alldicdata);
NSArray *results=[alldicdata objectForKey:@"results"];
NSLog(@"%@",results);
NSString *str=nil;
//    for(int j=0;j<results.count;j++)
//    {
//        str=[NSString stringWithFormat:@"%@,%@",str,[results objectAtIndex:i]];
//    }
NSLog(@"%@",str);
for(NSDictionary *dict in results){

    NSMutableDictionary *data=[[NSMutableDictionary alloc] init];
    [data setObject:[dict objectForKey:@"formatted_address"] forKey:@"formatted_address"];
    NSMutableArray *dataStore=[[NSMutableArray alloc]init];
    [dataStore addObject:data];
    [data release];
     str=[NSString stringWithFormat:@"%@,%@",str,[dataStore objectAtIndex:i]];
    NSLog(@"%@",str);

}
NSDictionary *d=[results objectAtIndex:0];
NSArray *a=[d objectForKey:@"formatted_address"];
NSLog(@"%@",a);
return a;
}

//EDIT updated code for annotation

 - (float)getHeadingForDirectionFromCoordinate:(CLLocationCoordinate2D)fromLoc toCoordinate:(CLLocationCoordinate2D)toLoc
{
float fLat = degreesToRadians(fromLoc.latitude);
float fLng = degreesToRadians(fromLoc.longitude);
float tLat = degreesToRadians(toLoc.latitude);
float tLng = degreesToRadians(toLoc.longitude);

float degree = radiandsToDegrees(atan2(sin(tLng-fLng)*cos(tLat), cos(fLat)*sin(tLat)-sin(fLat)*cos(tLat)*cos(tLng-fLng)));

if (degree >= 0) {
    return degree;
} else {
    return 360+degree;
}
}

- (CLLocationDistance)distanceBetweenCoordinate:(CLLocationCoordinate2D)originCoordinate andCoordinate:(CLLocationCoordinate2D)destinationCoordinate {

CLLocation *originLocation = [[CLLocation alloc] initWithLatitude:originCoordinate.latitude longitude:originCoordinate.longitude];
CLLocation *destinationLocation = [[CLLocation alloc] initWithLatitude:destinationCoordinate.latitude longitude:destinationCoordinate.longitude];
CLLocationDistance adistance = [originLocation distanceFromLocation:destinationLocation];
[originLocation release];
[destinationLocation release];

return adistance;
}
-(CGFloat)calculateDistanceBetweenSource:(CLLocationCoordinate2D)firstCoords   andDestination:(CLLocationCoordinate2D)secondCoords
{

// this radius is in KM => if miles are needed it is calculated during setter of Place.distance

double nRadius = 6371;

// Get the difference between our two points

// then convert the difference into radians

double nDLat = (firstCoords.latitude - secondCoords.latitude)* (M_PI/180);
double nDLon = (firstCoords.longitude - secondCoords.longitude)* (M_PI/180);

double nLat1 =  secondCoords.latitude * (M_PI/180);
double nLat2 =  secondCoords.latitude * (M_PI/180);

double nA = pow ( sin(nDLat/2), 2 ) + cos(nLat1) * cos(nLat2) * pow ( sin(nDLon/2), 2 );

double nC = 2 * atan2( sqrt(nA), sqrt( 1 - nA ));

double nD = nRadius * nC;

//NSLog(@"Distance is %f",nD);

return nD; // converts to miles or not (if en_) => implicit in method
} 

//annotation update

appDel=(AppDelegate *)[UIApplication sharedApplication].delegate;
NSLog(@"%@",self.petID);
DatabaseController *dbObj=[[DatabaseController alloc] init];
NSString *query=[NSString stringWithFormat:@"select * from petBoundarySettings where petId=%@",self.petID];
NSLog(@"%@",query);
NSLog(@"%@",[appDel getDBPath]);
NSMutableArray *alertSettingArray=[dbObj getPetAlertSerrings:query :[appDel getDBPath]];
if([alertSettingArray count]>0){
    distance=[[[alertSettingArray objectAtIndex:0] objectForKey:@"distance"] integerValue];
address=[[alertSettingArray objectAtIndex:0] objectForKey:@"address"];
lat2=[[alertSettingArray objectAtIndex:0] objectForKey:@"lat"] ;
    NSLog(@"%@",[[alertSettingArray objectAtIndex:0] objectForKey:@"lat"]);
  lon2=[[alertSettingArray objectAtIndex:0] objectForKey:@"lang"] ;
    NSLog(@"%@",[[alertSettingArray objectAtIndex:0] objectForKey:@"lat"]);
    //self.locId=[[[alertSettingArray objectAtIndex:0] objectForKey:@"locId"] integerValue];
   // self.pettracking=[[[alertSettingArray objectAtIndex:0] objectForKey:@"petTracking"] integerValue];
}
UIImageView *imageNav = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"sml-cat_03.png"]];
//[self.navigationController.navigationBar addSubview:imageNav];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:imageNav];
//[self.navigationController.navigationBar sendSubviewToBack:imageNav];
[imageNav release];

NSLog(@"%@",alertSettingArray);
[dbObj release];

/*UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"icon_menu.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(menu:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 40, 32)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];*/
MKCoordinateSpan span;
span.latitudeDelta=.01;
span.longitudeDelta=.01;
MKCoordinateRegion region;
//distance=appDel.alertDistance;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = nil;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];

currentAnnotation=[[MyAnnotations alloc]init];
NSLog(@"%f",appDel.getlat);
NSLog(@"%f",appDel.getlon);
regionCoordinate.latitude =[lat2 floatValue];
regionCoordinate.longitude = [lon2 floatValue];
//regionCoordinate.latitude =appDel.lat;
//regionCoordinate.longitude = appDel.lon;

currentAnnotation.coordinate=regionCoordinate;
currentAnnotation.title=@"Boundary Location";
currentAnnotation.subtitle=appDel.address;



// Configure the new event with information from the location
//CLLocationCoordinate2D coordinate = [location coordinate];
region.center=CLLocationCoordinate2DMake(regionCoordinate.latitude,regionCoordinate.longitude);
//NSLog(@"%@",location);
region.span=span;
[_myMapView setRegion:region animated:YES];
[_myMapView regionThatFits:region];

region1=region;
//Pet Location:

petAnnotation=[[MyAnnotations alloc]init];
petCoordinate.latitude = +11.028549739;
petCoordinate.longitude = +76.89644586;

petAnnotation.coordinate=petCoordinate;
petAnnotation.title=@"Pet Location";
petAnnotation.subtitle=@"Vadavalli";

MKCircle *circle = [MKCircle circleWithCenterCoordinate:regionCoordinate radius:distance];

[_myMapView addOverlay:circle];
//CLLocation *locationB = [locationManager location];
CLLocation *whereIAm = [locationManager location];
NSLog(@"%@",whereIAm);
//NSLog(@"I'm at %@", whereIAm.description);
//whereIAm.
 [_myMapView addAnnotation:currentAnnotation];
//[_myMapView addAnnotation:petAnnotation];
//mapView.mapType=MKMapTypeStandard;
//locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;


//locationManager.distanceFilter=50;
// CLLocationDistance meters = [location distanceFromLocation:petAnnotation];

//CLLocationDistance distance = [petCoordinate distanceFromLocation:coordinate];


MKMapPoint p1 = MKMapPointForCoordinate(regionCoordinate);
MKMapPoint p2 = MKMapPointForCoordinate(petCoordinate);
//locationManager.delegate = self;
    //Calculate distance in meter
CLLocationDistance dist = MKMetersBetweenMapPoints(p1, p2);
NSLog(@"%f",dist);
//In miles
i=0;
//NSLog(@"%f",dist);

//NSLog(@"%f",[self calculateDistanceBetweenSource:regionCoordinate andDestination:petCoordinate]);

//NSLog(@"%f",[self distanceBetweenCoordinate:regionCoordinate andCoordinate:petCoordinate]);

//[self performSelector:@selector(animateFlash) withObject:nil afterDelay:FLASH_INTERVAL+2.0];
[self getPetData];
timer= [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(getPetData) userInfo:nil repeats:YES];
if(appDel.checkGPS==NO)
{
    [self getPetDataFromGPS];
}

Can any please help me to sort it out.

share|improve this question
the code above doesn't show any updating ... it shows you providing views for the markers only -- show us how you update the coordinates – Daij-Djan Apr 6 at 9:17
@Daij-Djan Question updated.Please check – fazil Apr 6 at 9:19
same thing.. you never update the annotations – Daij-Djan Apr 6 at 9:21
@Daij-Djan Please check the updated code – fazil Apr 6 at 9:34
nope :D still nothing.. again: you never assign a new coordinate to the annotations – Daij-Djan Apr 6 at 9:47
show 1 more comment

closed as too localized by Daij-Djan, Carl Veazey, Rachel Gallen, nneonneo, Paulo Scardine Apr 8 at 0:41

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

you never update your annotations so how should they be reflected on the mpaview? they never change :)

you somewhere in your code need to move the annotations.

e.g.

- (void)locationOfPetChangedTo:(CLLocationCoordinate2D)coord { petAnnotation.coordinate = coord; }

EDIT you show all the code now -- and it looks like you're instead of updating the petAnnotation you always alloc init a new one -> so the one on the map is not updated.

share|improve this answer
Coding Updated in question – fazil Apr 6 at 9:34
you still dont update the annotation – Daij-Djan Apr 6 at 9:48
I did Can you please check now.PLease do the needfully – fazil Apr 6 at 9:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.