4

I have used the classes provided by apple CrumbPath.o and CrumbPathView.o, but it supports only iphone 5.0,when I try the same code with iphone 4.0 ,it does not update the route. Code :

 if (newLocation)
    {

    if (oldLocation.coordinate.latitude == 0.0) {
        initialLocation = [[[CLLocation alloc]initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude]retain];
    }
    // make sure the old and new coordinates are different
    if((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) &&
      (oldLocation.coordinate.longitude != newLocation.coordinate.longitude))
    {    
    if (!crumbs)
    {
        // This is the first time we're getting a location update, so create
        // the CrumbPath and add it to the map.
        //
        crumbs = [[CrumbPath alloc] initWithCenterCoordinate:newLocation.coordinate];
        [mapView addOverlay:crumbs];

        // On the first location update only, zoom map to user location
        MKCoordinateRegion region = 
        MKCoordinateRegionMakeWithDistance(newLocation.coordinate, 2000, 2000);
        [mapView setRegion:region animated:YES];
    }
    else
    {
        // This is a subsequent location update.
        // If the crumbs MKOverlay model object determines that the current location has moved
        // far enough from the previous location, use the returned updateRect to redraw just
        // the changed area.
        //
        // note: iPhone 3G will locate you using the triangulation of the cell towers.
        // so you may experience spikes in location data (in small time intervals)
        // due to 3G tower triangulation.
        // 
        Count++;
        double latitude = 0.000500 * Count;
        double longitude = 0.000020 * Count;
        _bean = [[TempBean alloc]init];
        _bean.lat = newLocation.coordinate.latitude + latitude;
        _bean.lon = newLocation.coordinate.longitude - longitude;



        CLLocation *locationToDraw = [[CLLocation alloc]initWithLatitude:_bean.lat longitude:_bean.lon];
        //                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Update_Loc" message:[NSString stringWithFormat:@"Lat:%f , Lon:%f",locationToDraw.coordinate.latitude,locationToDraw.coordinate.longitude] delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@"Cancel",nil];
        //                [alert show];
        //                [alert release];

        MKMapRect updateRect = [crumbs addCoordinate:locationToDraw.coordinate];

        if (!MKMapRectIsNull(updateRect))
        {
            // There is a non null update rect.
            // Compute the currently visible map zoom scale
            MKZoomScale currentZoomScale = (CGFloat)(mapView.bounds.size.width / mapView.visibleMapRect.size.width);
            // Find out the line width at this zoom scale and outset the updateRect by that amount
            CGFloat lineWidth = MKRoadWidthAtZoomScale(currentZoomScale);
            updateRect = MKMapRectInset(updateRect, -lineWidth, -lineWidth);
            // Ask the overlay view to update just the changed area.
            [crumbView setNeedsDisplayInMapRect:updateRect];
        }
        [self calDistance:initialLocation SecondCor:locationToDraw];
        [locationToDraw release];
        locationToDraw =nil;
        [_bean release];
        _bean = nil;


}}
Ankur
  • 5,086
  • 19
  • 37
  • 62
Te Amo
  • 117
  • 3
  • In which method does this block of code sit in? Is it in `locationManager:didUpdateLocations` or `locationManager:didUpdateToLocation:FromLocation`? You should have both since iOS6+ will use the first and iOS5- the latter. Have you try debugging? Was these block of code gets called? – Mysteltainn Sep 17 '14 at 08:08
  • Wrote in locationManager:didUpdateToLocation:FromLocation...yep i debugged....it gets called! – Te Amo Sep 18 '14 at 11:56

1 Answers1

0

If that the case then, you should try looking into your CrumbPathView.m see if the render function works correctly or not from what i see here you copied & pasted the code from Apple Docs right? In the file you should find this in method drawMapRect:zoomScale:inContext:

if (path != nil)
{
    CGContextAddPath(context, path);
    CGContextSetRGBStrokeColor(context, 0.0f, 0.0f, 1.0f, 0.6f);
    CGContextSetLineJoin(context, kCGLineJoinRound);
    CGContextSetLineCap(context, kCGLineCapRound);
    CGContextSetLineWidth(context, lineWidth);
    CGContextStrokePath(context);
    CGPathRelease(path);
}

See if the path is nil or not if it's nil-ed nothing gets rendered. Have you debug into this view? The rendering happens in CrumbPathView so, you should see what happen in it.

If the path is nil then you should check the method which is called to assign its value, located above the if (path != nil)

Mysteltainn
  • 421
  • 3
  • 5
  • 13
  • @Te Amo I'm written this comment as an answer because I have to pasted the block of code which would be hard to read if posted in comments. – Mysteltainn Sep 30 '14 at 08:21