Showing current location as well as another location in iphone

whenever we load the mapview, it automatically shows the current location of the user. In my case, I am showing a different location on the map, so that the map loads the current location and scales to the location I gave .. but the current location point was not showing (the blue one that appears automatically). I gave mapView.showCurrentLocation = TRUE; but it is not shown. so can anyone tell how it works and it should tell the current location label and then zoom up to the point I gave. thanks

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    static NSString *defaultPinID = @"CameraAnnotation";
    MKPinAnnotationView *retval = nil;
    static int postag=1;

    (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if(annotation=MapView.userLocation)
    {
        return nil;
    }
    // If we have to, create a new view
    else    if (retval == nil)
    {
        retval = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

        UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        myDetailButton.frame = CGRectMake(0, 0, 50, 23);
        myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        myDetailButton.tag=postag;
        postag++;
        [myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];
        retval.rightCalloutAccessoryView = myDetailButton;
        [retval setPinColor:MKPinAnnotationColorRed];
        retval.animatesDrop = YES;
        retval.canShowCallout = YES;
    }

    return retval;
}

      

+2


a source to share


2 answers


In the simulator, the default current location is Cupertino. This is what you see, it will work correctly on the device.

Moreover, you have to use CLLocationManager to get the current location.

- (void)applicationDidFinishLaunching:(UIApplication *)application { 
{
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self; // Tells the location manager to send updates to this object
[locationManager startUpdatingLocation];
}

      



To change the color of contacts

MKPinAnnotationView   *pin=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"]autorelease];

[pin setPinColor:MKPinAnnotationColorRed];

      

All the best.

+2


a source


take a look at the answer on this question to set the zoom level of the MkMapView to cover all MKAnnotations attached to it



+1


a source







All Articles