How can I Resize the MKCircleView? - iphone

I am Trying to Resize MkCircle Through finger touch. How can I start this? can any one suggest me?
Thanks for advance.

I draw the custom circle above the map view with same radius look like circle.
Finding edge point of MKcirlce
convert center point CLLocationCoordinate2D to MKMapPoint
MKMapPoint centerMapPoint = MKMapPointForCoordinate(centerCoordinate)
Calculate MKMapSize of the circle and get width
double circleMapSize = mkCircle.boundingMapRect.size.width
3.create a point on the perimeter of the circle.
MKMapPoint leftMostPoint = MKMapPointMake(centerMapPoint.x - circleMapSize/2.0, centerMapPoint.y)
Now get CLLocationCoordinate2D point from leftMostPoint
CLLocationCoordinate2D leftMostCoordinateOnCircle = MKCoordinateForMapPoint(leftMostPoint)
So now i have center point and edge point then convert it to (x,y) of ios coordinates.
CGPoint myPoint = [self.MapView convertCoordinate:originalCoordinate toPointToView:self.MapView];
CGPoint edgePoint = [self.MapView convertCoordinate:originalCoordinate toPointToView:self.MapView];
then i calculate distance b/w those two points using pythagoras theorem
int distnce1=sqrt(powf(edgePoint.x- myPoint.x, 2) + powf(edgePoint.y-myPoint.y, 2));
int finalWidth=2*distnce1;
Then i set distance to custom circle width and height
after pich Gesture end again i try to get edge lattitude and longitude of custom circle by using circle maths
float x = circleView.frame.size.width/2 * sin(0)+circleView.center.x;
float y = circleView.frame.size.width/2 * cos(0)+circleView.center.y;
convert x,y into coordinates
CLLocationCoordinate2D select_coordinate = [self.MapView convertPoint:point toCoordinateFromView:self.view];
then i find distance b/w new coordinates and center point of MKCircle then change the radius of MKCirlce equal to Distance.

One approach which might be simplest is to actually draw the circle yourself above the map view, on a separate transparent view which responds to touch events. Then, when drawing is complete, hide that view but add an actual MKCircle to the map view with the same graphical settings.
Typically it's easier to handling drawing/gestures outside of the map view for things like this.

Related

ios MapKit, following a path

I have a path rendering on my map. I have a series of waypoints and I'm simulating movement through them.
When changing the display region it appears that my coordinate when converted to a CGPoint is floorf by Apple's implementation. This causes a very jittery appearance instead of a smooth one.
Is there anyway to get around this?
[m_mapView setRegion: MKCoordinateRegionMake(coord, MKCoordinateSpanMake(0, 0))];
The map then tries to center on this given point. However the point may not be pixel aligned as can be view by the following function.
CGPoint point = [m_mapView convertCoordinate:coord toPointToView:m_mapView];
Thus the mapview floors the centerpoint's result to align all pixels for the underlying map.
I make the view larger than the screen to account for the offset and to avoid clipping.
I simulate a point moving along the route and place it using an annotation and then center on that point at 30 frames per second.
Assume coord is the position of the moving point.
[m_mapView setCenterCoordinate: coord];
CGPoint p = [m_mapView convertCoordinate:m_mapView.centerCoordinate toPointToView:m_mapView];
CGPoint p1 = [m_mapView convertCoordinate:coord toPointToView:m_mapView];
CGPoint offset = CGPointMake(p.x - p1.x, p.y - p1.y);
CGRect frame = CGRectInset(CGRectMake(0.0f, 0.0f, 1024.0f, 1024.0f), -50.0f, -50.0f);
frame.origin.x+= offset.x;
frame.origin.y+= offset.y;
[m_mapView setFrame: frame];

Auto scroll mkmapview when dragging pin

Is there any good code which implements auto scrolling of MKMapView when dragging pin?
The effect I'm trying to achieve is a map scrolling when I drag the pin and reach edges of the map. When I move pin out of the edges I expect scrolling to stop and when I drop it, map shell move until pin reaches center of the screen.
I know how to center map on chosen location, but I'm not really have an idea how to scroll it while dragging pin.
It would really help if someone could just direct me to a logic of the way how to implement it.
MKMapRect mapRect = [self.mapView visibleMapRect];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(42.777126,-76.113281);
MKMapPoint point = MKMapPointForCoordinate(coordinate);
mapRect.origin.x = point.x - mapRect.size.width * 0.3;
mapRect.origin.y = point.y - mapRect.size.height * 0.70;
[self.mapView setVisibleMapRect:mapRect animated:YES];

OpenGL Ortho Coordinates

I have an OpenGL view overlaid on top of an MKMapView. My goal is to have the coordinates of the glView to have the same values of the MKMapPoints on the map. To do this I found the values for the MKMapPoint on the top left and the bottom right of the map.
CLLocationCoordinate2D coordinateTopLeft = [mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:mapView];
MKMapPoint pointTopLeft = MKMapPointForCoordinate(coordinateTopLeft);
CLLocationCoordinate2D coordinateBottomRight = [mapView convertPoint:CGPointMake(mapView.frame.size.width, mapView.frame.size.width) toCoordinateFromView:mapView];
MKMapPoint pointBottomRight = MKMapPointForCoordinate(coordinateBottomRight);
Then I set the right, left, bottom, and top coordinates of the glView to match these points accordingly.
glOrthof(pointTopLeft.x, pointBottomRight.x, pointBottomRight.y, pointTopLeft.y, -1, 1);
Unfortunately, this did not work. The triangles that I tried to draw did not work. I tested and the points that I was trying to draw were located in the correct domain.
Am I just misunderstanding how the glOrthof method works?
Have you tried flipping pointBottomRight.y and pointTopLeft.y? The OpenGL y-coordinate system is inverted from most commonly used conventions.

Move MKMapView point to pixel coordinates

I have a quick question. I am using a custom view as a callout accessory for my map view. I am having some issues with getting the annotation to move to the right bottom corner of the said view. I am currently trying to get the CGPoint coords of the selected annotation, but beyond that I've drawn a blank Any help would be greatly appreciated.
The current code I'm using (I know it is incorrect is:)
CGPoint bottomLeftPoint = CGPointMake(xOffset,[self.internalAnnotationCallout view].frame.size.height);
CLLocationCoordinate2D bottomLeftCoord = [self.branchLocation convertPoint:bottomLeftPoint toCoordinateFromView:self.branchLocation];
MKCoordinateSpan span = {latitudeDelta: kMapMultiLatDelta, longitudeDelta: kMapMultiLatDelta};
MKCoordinateRegion region = {bottomLeftCoord, span};
[self.branchLocation setRegion:region animated:YES];
//[self.branchLocation setCenterCoordinate:newCenterCoordinate animated:YES];
EDIT:
Ok so I messed around with this a little and was able to to put something together that seems to work, hoping that I now actually understand what you're trying to achieve!
- (void)shiftToCorner{
//ignore "Annotation", this is just my own custom MKAnnotation subclass
Annotation *currentAnnotation = [[mapView selectedAnnotations] objectAtIndex:0];
[mapView setCenterCoordinate:currentAnnotation.coordinate];
CGPoint fakecenter = CGPointMake(20, 20);
CLLocationCoordinate2D coordinate = [mapView convertPoint:fakecenter toCoordinateFromView:mapView];
[mapView setCenterCoordinate:coordinate animated:YES];
}
Let me quickly explain what this does; Let's say you want your annotation to move to a position 20 points in from the right edge and 20 points up from the bottom edge of the map view. If you think about it, if the current annotation is at the center of the map view, then the distance to this point is the same as the distance to (20, 20). This means that we can send our annotation to this point by first centering our map view on the annotation, then animating to (20, 20).

iOS CoreLocation plot user location on top of image

i'm trying to create a building navigation application similar to http://navigationapps.com/wp-content/uploads/2010/10/point-inside-2.png . I'm planning on displaying the building floor plan image as a UIImageView and using CoreLocation to get the longitude and latitude coordinates for the pin pointer. The next step - which im also stuck on, how do i plot the point on the image? - i am already able to retrieve the users lat and lot coordinates ..
Well, you firstly a UIImageView to display some sort of icon for the pin pointer, and then a function to transform lat/long coordinates into the position on your image.
Assuming your building floor plan image is aligned with north at the top,
- (CGPoint)plotPointOfLocation:(CLLocationCoordinate2D)location {
CLLocationCoordinate2D topLeftCoordinate = CLLocationCoordinate2DMake(/* the lat/long of the top-left of the plan image */);
CLLocationCoordinate2D bottomRightCoordinate = CLLocationCoordinate2DMake(/* the lat/long of the bottom-right of the plan image */);
CGSize planImageSize = CGSizeMake(/* the size of the plan image, as drawn on the screen, in pixels */);
CLLocationDegrees latSpan = bottomRightCoordinate.latitude - topLeftCoordinate.latitude;
CLLocationDegrees longSpan = bottomRightCoordinate.longitude - topLeftCoordinate.longitude;
CLLocationCoordinate2D offsetLocation = CLLocationCoordinate2DMake(location.latitude - topLeftCoordinate.latitude,
location.longitude - topLeftCoordinate.longitude);
CGPoint ret = CGPointMake((offsetLocation.latitude / latSpan) * planImageSize.width,
(offsetLocation.longitude / longSpan) * planImageSize.height);
return ret;
}
Then just set your pin UIImageView 'center' property to the value returned from this method.