Iphone development: Modify the blue user location of a map

Source: Internet
Author: User

Modify the view of the user's current location in mkmapview to the ui you need.
The effect is as follows:



The Code is as follows:

 
Source code here. Copy all. If some methods are missing (for image processing functions, leave a message)
-(MKAnnotationView *) mapView :( MKMapView *) mapView viewForAnnotation :( id <MKAnnotation>) annotation
{
If ([annotation isKindOfClass: [MKUserLocation class])
{
Static NSString * annotation_id = @ "annotation_id ";
MKPinAnnotationView * pinView = (MKPinAnnotationView *) [map_view dequeueReusableAnnotationViewWithIdentifier: annotation_id];
If (! PinView)
{
MKAnnotationView * annotationView = [[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: annotation_id] autorelease];
AnnotationView. canShowCallout = YES;
// Modify the blue image of the map @ "flag.png"
UIImage * annotation_image = [UIImage imageNamed: @ "flag.png"];
CGRect resizeRect;
ResizeRect. size = annotation_image.size;
CGSize maxSize = CGRectInset (map_view.bounds, 0.0, 0.0). size;
// This segment is used to process images, which can be omitted. The purpose here is to fear that the image is too large.
If (resizeRect. size. width> maxSize. width)
{
ResizeRect. size = CGSizeMake (maxSize. width, resizeRect. size. height/resizeRect. size. width * maxSize. width );
}
If (resizeRect. size. height> maxSize. height)
{
ResizeRect. size = CGSizeMake (resizeRect. size. width/resizeRect. size. height * maxSize. height, maxSize. height );
}

ResizeRect. origin = (CGPoint) {0.0f, 0.0f };
UIGraphicsBeginImageContext (resizeRect. size );
// If your image is of the proper size, you do not need to process it. Simply use your image.
UIImage * resize_image = [annotation_image imageByScalingAndCroppingForSize: CGSizeMake (45, 45)];
CGRect rect = CGRectMake (0.0, 0.0, 45, 45 );
[Resize_image drawInRect: rect];

UIImage * resizedImage = UIGraphicsGetImageFromCurrentImageContext ();
UIGraphicsEndImageContext ();

AnnotationView. image = resizedImage;
AnnotationView. opaque = NO;
Return annotationView;
}
Else
{
PinView. annotation = annotation;
}
Return pinView;
}
Return nil;
}
 



From cloud huaikong-abel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.