Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-16-2011, 04:25 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 4
rsxchaps is on a distinguished road
Default Expert help on mapView overlays

I have been working on this overlay in iOS for weeks on end now and at this point I am completely stumped. I have utilized all of apples sample code examples as well as WWDC videos and pdf resources on the site. As a last resort I'm posting this questions in hopes for some guidance. I have a mapView that I can drop custom annotations on/zoom in/zoom out/etc. My goal is to create an overlay that will place an arrow on the custom annotation that the user touches/creates. The very tip of the arrow needs to be at the exact lat/lon of the pin dropped. Essentially anchoring that point so when I pass the arrow overlay a wind direction it will rotate accordingly. almost as if you dropped the point of a protractor on the annotation and then rotated around a radius. I ended up getting this cool method to work with MKPolygon and it was perfect but I cant go that route because I have custom arrows/images that are png's that need to be used.

I can post my code but it's pretty self explanatory. Create an Overlay that conforms to the MKOverlay protocol. Create a overlayView that conforms to the MKOverlayView protocol. Lastly within the MKMapView define the respective delegate methods ex - (MKOverlayView *)mapViewMKMapView *)mapView viewForOverlayid )overlay.

If it helps at all I can get the overlay to appear on the map within my mapOverlayView class by creating a UIImage and then putting that in a UIImageView. It appears by default to line up the top left corner of the view with the center of the annotation. This is great but when I try anchor the imageView or rotate the imageView it becomes off center and turns into a mess. I thought I had a hunch when watching a video on mercator projection and MKMapPoint but to no avail I am still stumped.

Thank you in advance for any direction you can provide.
rsxchaps is offline   Reply With Quote
Old 11-17-2011, 06:38 PM   #2 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 4
rsxchaps is on a distinguished road
Default

I took a break from the project today. I've posted the relevant code for the overlay classes. Maybe another set of eyes will get me on the right track. The whole anchor point issue really gets to me. I have to be doing something wrong. Thanks!


Code:
//***********MKOverlayView class below ************

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:       (CGContextRef)context 

{
UIImage *image = [UIImage imageNamed:@"arrow.png"];

UIImageView *imageView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(0.0, 0.0, image.size.width, image.size.height) ];

[imageView setImage:image];

//imageView.layer.anchorPoint = CGPointMake(1.0f, 0.5f);    

//CGFloat radian = windDirection * M_PI/180;

// CGAffineTransform rotate = CGAffineTransformMakeRotation(-radian);

//  imageView.transform = rotate;    

imageView setCenter:CGPointMake(0.5f, 0.5f)];

//[imageView.layer setPosition:CGPointMake(-60.0f,15.0f)];

// Wind direction = 90.00000 for a test case

CGFloat radian = windDirection * M_PI/180;

 //[self rotateImage:image withAngle:windDirection*M_PI/180];    

imageView.layer.anchorPoint = CGPointMake(0.5, 1.0);

CGAffineTransform rotate = CGAffineTransformMakeRotation(-radian);

imageView.transform = rotate;    

 [self addSubview:imageView];    

  }
//*********//MKOverlay class below ******************

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate converted:(CGPoint)convCoord
{

self = [super init];

if (self != nil) {

lat = coordinate.latitude;

lon = coordinate.longitude;

// Values match up with coordinates from mapView. This checks out. 
NSLog(@"Coords getting passed in to initwithcoords are %f %f",lat, lon);

     }

return self;

}


 - (CLLocationCoordinate2D)coordinateForCone

 {

CLLocationCoordinate2D coord1 = { lat, lon };

  return coord1;
  }
- (MKMapRect)boundingMapRect

{
 MKMapPoint upperLeft = MKMapPointForCoordinate([self coordinateForCone]);

  MKMapRect bounds = MKMapRectMake(upperLeft.x,     upperLeft.y,2000,2000);//500*longitudeMultiplier, 910*latitudeMultiplier);

return bounds;
}
rsxchaps is offline   Reply With Quote
Reply

Bookmarks

Tags
ios, mapview, objective-c, overlay, rotate

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 395
17 members and 378 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, chiataytuday, dre, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, QuantumDoja, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0