I am trying to animate the movement of a GMSmarker (or any object for that sake), between 2 points.
(Just to clarify this is using either Apple Maps or Google Maps)
So I would have the initalPoint, and the newPoint, and it would animate the icon that is marking 'position' from intialPoint to newPoint.
I have rigorously searched the Google Maps SDK myself but couldn't find anything that would do it.
Can anyone provide and code samples/tutorials on how to do such a thing?
You could overlay your own custom "marker" and animate it using UIView animations. For example, the following code would move a red square from pointA to pointB.
- (void)moveMarker
{
CGPoint pointA = CGPointMake(30, 40);
CGPoint pointB = CGPointMake(120,65);
UIView *marker = [[UIView alloc] initWithFrame:
CGRectMake(pointA.x, pointA.y, 10, 10)];
marker.backgroundColor = [UIColor redColor];
[mapViewIWantToAddAMarkerTo addSubview:marker];
[UIView animateWithDuration:5 animations:^{
marker.frame = CGRectMake(pointB.x, pointB.y, 10, 10);
}];
}
I now have this working. The way to do this is to simple update the location of a MKPointAnnotation (using apple maps)
In swift it goes:
var thePoint : MKPointAnnotation()
thePoint.setCoordinates([CLLocationCoordainte2D variable goes here])
Do this multiple times a second and it appears to smoothly move.
Related
I want to show completely GMSCircle on MapView but radius of circle is dynamically changed.
When radius is changed then MapView will be automatically adjust to view the complete circle on map to show all marker.
In Swift language, I have found a solution which may be helpful for me as given here: Change Camera Zoom based on Radius Google Maps iOS SDK
But I have to implement this in Objective-c and in Objective-c we didn't have bound property for GMSCircle.
Thanks in Advance,Please guide me.
you have to set zoom level according to your radius
// SET ZOOM LEVEL
int zoomLevel = 11;
double radius = raduismeter+ raduismeter / 2;
double scale = radius / 500;
zoomLevel = (int) (16 - log(scale) / log(2));
zoomLevel++;
you have to set and calculate zoom level according to your need. Than you have to set radius circle
GMSCircle *geoFenceCircle = [[GMSCircle alloc] init];
geoFenceCircle.position =PinDropCoordinates;
geoFenceCircle.strokeWidth = 0.5;
geoFenceCircle.strokeColor = [UIColor redColor];
NSLog(#"%#",geoFenceCircle);
geoFenceCircle.radius =5000.00;
geoFenceCircle.map = self.mapView;
After setting circle you have to animate your Camera accordingly.
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:3] forKey:kCATransactionAnimationDuration];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:PinDropCoordinates.latitude
longitude:PinDropCoordinates.longitude zoom:zoomLevel];
[self.mapView animateToCameraPosition: camera];
[CATransaction commit];
I wants to draw polyline for walk like google map app in ios using google maps ios sdk. For more clear understanding i am uploading image that is from google map app(ios.)
Are you asking how to achieve the dotted polyline effect? If so, I don't believe that is supported in the SDK.
You can manually create a similar effect with GMSCircles.
for(int x = 0; x < [self.path count]; x++)
{
CLLocationCoordinate2D coord = [self.path coordinateAtIndex:x];
//draw circle coord
GMSCircle *circle = [GMSCircle circleWithPosition:coord radius:20];
circle.fillColor = [UIColor blueColor];
circle.strokeColor = [UIColor blackColor];
circle.strokeWidth = 2;
circle.map = mapView;
}
For this to really look like the original example you will probably need to add additional points onto the line in order for the circles to be evenly spaced out. For that you could do something like this.
for(all the points in the path)
{
if(the distance from pointA to pointB is > some distance)
{
centerPtr = center point of pointA and pointB
insert centerPt in path
}
}
You can turn this into a simple recursive function that should give you something similar to what you are looking for.
Currently i am trying to implement the following. While making a compass, i would like to draw arrows(circles) at set locations and rotate around my view to display on compass.
I can use storyboard to create Imageviews and the like and parent them with one another.
I am trying to now do this programming code, as that when a new location is received by program it can display the new point on compass.
I have already worked out code to rotate around
Ideally my flow of code should be as follows:
For i = 1 to 5;
Draw empty square view[i]
Draw Circle and position within square[i] at co-ordinate (x,y) (pretty much at the north point of compass)
Parent circle to Square
Rotate square[i] to x degrees.
Next i
My question is how do i programmatically draw these views and then how do i parent the views. Such that i can rotate one with the other at a fixed point.
Thanks.
this is not exact answer, but it may help you.just play with value of i(loop index)
-(void) rotateOn360Degree
{
int x,y;
double radious=30;
for(int i=1;i<=360;i++)
{
x = radious* cos((i * 3.14) / 180));
y = radious* sin((i * 3.14) / 180));
UIView *tmpView = [[UIView alloc] init];
[tmpView setBackgroundColor:[UIColor greenColor]];
[tmpView.layer setCornerRadius:5];
tmpView.frame = CGRectMake(x,y, 10, 10);
[self.view addSubview:tmpView];
}
}
My app will use a Pan Gesture to allow you to pan gesture a container view within a view controller to the right to display a menu hidden behind the container view. (similar to how the YouTube app lets the user pan his/her finger to the right to bring up the main menu OR how the default lock screen lets you pan to the right to reveal the passcode keypad)
- (IBAction)testPan:(UIPanGestureRecognizer *)sender
{
CGPoint translation = [sender translationInView:self.view];
CGPoint location = [sender locationInView:self.view];
CGPoint velocity = [sender velocityInView:self.view];
_theView.frame = CGRectMake( translation.x, 50, 300, 300);
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(#"All fingers are lifted");
_theView.frame = CGRectMake( 10, 50, 300, 300);
}
}
So what I'd like to do right now is make sure that this line:
_theView.frame = CGRectMake( 10, 50, 300, 300);
After the if statement happens gradually rather than instantly as it does right now.
My plan initially was to use a loop that would take the value "translation.x" and gradually through milliseconds make it equal to 10 to give the pan gesture an animated looking effect.
But apparently Objective-C doesn't allow you to sleep() for milliseconds, I'm guessing they don't allow this for efficiency purposes.
So how could I make a float value go from x to 10 within 2 seconds rather than instantly?
Does CGRect already include something to do this for you automatically to transform a shape over time?
The exact mechanism to do what you want is built into the view system and very easy to use:
[UIView animateWithDuration:2.0 animations:^{
_theView.frame = CGRectMake(10, 50, 300, 300);
}];
You basically give UIView a duration (2 seconds) and a block inside of which you make direct changes to any animatable view properties (like frame), which will then happen over the course of the duration. (So rather than managing a timer yourself and updating your rect and then the frame, you can just tell the system to animate the frame directly.)
I have a 3x3 grid of UIViews with UIGestureRecognizers added to them, arranged like so:
The way it works is that tapping on a square enlarges it 2x using CGAffineTransformScale and overlays that over the other squares. The problem is that the touch area stays the same size as the 1.0 scale for some reason.
I add the squares using
CGRect squareFrame = CGRectMake(1 + squareSpacing + ((squareDimension + squareSpacing) * i), topMargin, squareDimension, squareDimension);
SquareView *square = [[SquareView alloc] initWithFrame:squareFrame];
[square setPosition:i];
square.layer.zPosition = 0;
[self.view addSubview:square];
[squaresArray addObject:square];
The Squares have gesture recognizers added in their init:
fingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped:)];
[self addGestureRecognizer:fingerTap];
The tapped function does the following:
[UIView animateWithDuration:1.0
delay:0.0
usingSpringWithDamping:0.8
initialSpringVelocity:10.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGAffineTransform transform = self.transform;
self.transform = CGAffineTransformScale(transform, 2.0, 2.0);
}
completion:nil];
I outlined the touch area in red. I have tried playing with the zPosition but I don't know what to do to make it work, I am stuck. I want to be able to tap the enlarged square anywhere for it to close, but I am limited to the red area.
Thanks in advance.
EDIT: Sorry that the pictures are so large. Code added.
Steven
You might trying bringing the expanded UIView to the front of your parent view so that your tap events aren't captured by any overlapped views:
[parentView bringSubviewToFront:tappedView];