Search code examples
iphonemkmapviewcurrentlocation

Custom icon and default current location icon on Map when needed in iPhone


I have an application where in I give user 2 options. 1. Select your current location through GPS 2. Enter your current location manually.

What I want is When user has selected thh first option then I have to display the blue animated icon for current location And when user has selected 2nd option then I have to display my own custom icon for current location.

Is it possible? Suggestions are most welcomed.

Thanks.


Solution

  • First set a boolean variable for Example isInGPSMode

    now apply following code

    if(isInGPSMode==TRUE)
    {
         mapViewHome.showsUserLocation=TRUE;
    }
    else
    {
         mapViewHome.showsUserLocation=FALSE;
    }
    

    and handle the map view delegate as

    - (MKAnnotationView *) mapView:(MKMapView *)mapView1 viewForAnnotation:(id <MKAnnotation>) annotation
    {
        if(annotation==mapViewHome.userLocation)
        {
            return nil;
        }
        addAnnonation *tempAnnonation=(addAnnonation *)annotation;
    
        MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
        annView.pinColor = MKPinAnnotationColorRed;
        return annView;
    
    }
    

    for further details refer the link http://developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.html

    hope this helps