whenever we load a mapview ,it automaticallay shows the current user location right. In my case i am showing another locati开发者_如何转开发on on map ,such that the map loads the current location and zoomed to the location i have given .. but, the current location point was not showing (the blue one which comes automaticay..). i have given mapView.showCurrentLocation=TRUE; but its not showing . so could any one tells the way it works and it should say the current location mark and then zoomed to the point i have given. 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;
}
In simulator the default current location is Cupertino.This is what you are seeing, it will work properly in device.
More over you should 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 pin color
MKPinAnnotationView *pin=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"]autorelease];
[pin setPinColor:MKPinAnnotationColorRed];
All the best.
take a look at the answer on this question to set the MkMapView zoom level to encompass all the MKAnnotations attached to it
精彩评论