I have a MapView where I draw circle overlays with MKCircleView when the user taps the map which works fine but now I need to get all the location coordinates (lat/long) of the radius to store for later use to repopulate the map overlays. How can I get all the locations on the radius so I can show the circle again?
storing just the center point and the radius is not an option because I have to sync these points to a server
Store the center point and the radius. There are an infinite number of points within and on the boundary of any circle. If you need to draw a circle using data on the server, use the center and radius and whatever circle/ellipse function your drawing library has, or, if need be, use the center and radius and basic trigonometry to generate points on the circle to draw a polygon with. Or if you’re just feeding the data back down to your app, create your MKCircle objects with the class’s +circleWithCenterCoordinate:radius: method.
Related
Suppose I created a sphere mesh, uv-unwrapped it, and created 1000 texture maps around those unwrapped coordinates. Now I realized that I want some parts of the sphere to be "untextured" and have an option to texture them with another random texture. How would I remove the uv coordinates from the sphere so they don't get textured or at least move them to another uvmap without changing the position of the unwrapped coordinates.
I've created an app I've used geofence I want. Show a circle on the mapbox with the same radius as the geofence. The problem is that the circle is displayed and the size of the circle changes as the map is zoomed.
You probably don't want a proper circle feature. Rather, you want a polygon with many vertices that resembles a circle. This has been answered already with ready-to-use code here: Drawing a circle with the radius in miles/meters with Mapbox GL JS
I'm making an application that generates a 2D area (you can think of it as a drawing), with a camera hovering over it. The size of said drawing isn't known in advance, and could change greatly. After the "drawing" is generated, I want to position the camera so that the whole drawing is in view.
My original idea was to calculate the points that are at the top, bottom, left, and right of the drawing and having the camera move back, "zooming out" until they are all in sight, but there has to be a better way, right?
Assuming you are working in 2D (thus orthographic camera mode), you can set the camera's orthographicSize:
Camera.main.orthographicSize = height / 2F; //half of the height of the area
Then, set the aspect ratio (width / height):
Camera.main.aspect = 1F; //for example, a square area
I've made an application where it takes values from external file to create geometry. I'm very much successful in that. By default, my objects are viewing in very smaller in size. But when I tried with mouse ball rolling I can see the actual objects in the scene as it zooms into the scene. But, how could I obtain this size of objects as my scene is instantiated.
The link to working application : http://studenter.miun.se/~sagh0900/TrackBallAlt.Html
Here is the zoomed version view of scene and its objects
You can use either of these to get the size of the bounding box or sphere of your mesh.
// This computes it.
mesh.geometry.computeBoundingSphere();
// This gets it
var radius = mesh.geometry.boundingSphere.radius;
// Compute the bounding box
mesh.geometry.computeBoundingBox();
// This now has a min and max structure with x and y values of the box
mesh.geometry.boundingBox
Once you have that information you can set your camera so the objects are in view.
I am facing this problem while trying to rotate the map in my iPhone app
The view gets clipped and rotation also happens. I want to avoid the clipping. Any tips ?
heres the code:
viewToRotate.layer.transform = CATransform3DMakeRotation(0.8, 0., 0., 1.);
You need your map rotated in 3D ? If not (which is what I think you need), then just use CGAffineTransformMakeRotation (be careful, as it requires the angle in radians).
Also, if you don't want your map to be clipped, you need to make your map bigger, like in the image below (open in new tab to see it bigger)
http://img593.imageshack.us/img593/4498/calculatemapboundswhenr.png
First, you need to calculate the diagonal of the rectangle (your visible map) as instructed in the image above (which I call "radius" because that would be the radius of the smallest circle bigger than your rectangle).
Second, using the radius, you need to calculate the (smallest) square that will allow your map to be seen without clipping. This square will be used to set the bounds of your map (caution: NOT the frame - Apple specifies that, when using rotation, you should not use frame - just bounds and / or center).
Make sure this square is centered on the center of your visible map rectangle (i.e. the square should have X pixels above AND below the small rectangle ... and Y pixels left AND right of the small rectangle).
Hope it helps !
Did you ever figure out the solution?
The only way I could do it was to make the MapView in Interface Builder much bigger than the actual size of the screen area its supposed to cover, then I centered the MapView such that its center was in the center of the narrower viewable area.
Rotation seemed to work similarly to how it works in the built-in Maps app.
My guess is that you have to do this so that the image tiles streaming in from Google cover a wide enough area to "fill in the blanks" so to speak, even if they're not always visable.
If you apply a little math, you could probably programmatically size and position the MapView such that you void clipping, but don't require more tiles than is absolutely necessary.