CLLocationCoordinate2D distance between two points considering zoom level - ios

I'm trying to create a solid clustering mechanism using a subclass of an MKMapView. I came across a task that have I've been banging my head against the wall for quite some time now - grouping annotations into a single cluster when they're overlapping with one another. I can get the distance in meters between two annotations, but how can I get that distance relative to a zoom level (latitudeDelta)? Ideally I would like to know when two annotations overlap with each other considering their width and height for example are 40x40.

You can use convertCoordinate:toPointToView: to get the location of the actual screen point for an annotation:
CGPoint annotationPoint = [self.mapView convertCoordinate:annotation.coordinate
toPointToView:self.mapView];
After that, use your trigonometry skills to find the distance between two points.

Related

Calculate how many boxes and their center coordinate given an area of map

I have given a location defined by an area, example is Singapore area. Now I want to divide it into a circle given that each has radius of 50 KM. My objective is to find how many circles do I need to cover all the area of Singapore and what are the circle center coordinate.
Does someone know the formula of it and how do I do it in Python?
I found quite similar example here :
https://codesandbox.io/s/subbounds-8j0p6?file=/src/index.js:722-728
But I do need to know the idea behind it.

Is there an MKSquare in iOS?

I have a bunch of lat/long coordinates and I need to draw a square polygon around each one. Each square will be a set size (e.g. 50x50) with the coordinate in the centre. I see there is a MKCircle class but is there an MKSquare equivalent (I couldn't fine one but that doesn't mean there isn't) and if there isn't, any suggestions on how this could be achieved? I have done some searching and didn't produce any solid suggestions.
I would also like to make the square 3D as in if the map is tilted it would show a height kind of like buildings.
You can use MKPolygon for this. Simply provide four coordinates the correct distance from your center point and the four coordinates will form a square.

Converting real world location to screen coordinates

I want to ask this question without thinking about a specific technology. Suppose I pull a map tile from any maps provider using my real world location. How can I mark my location on this map tile? What is the calculation used here to convert longitude and latitude to pixels?
I have worked on OpenGL methods to view data on the earth and I think I'd summarize the position process as follows. This is by no mean the only way to do it by hopefully it helps you to think about the problem.
Treat the earth's core as the origin of a sphere, convert all polar coordinate of (latitude, longitude, radius) into (x,y,z) for every map points. Same thing for a particular mark you are interested in.
At this point, you would need to pick a view origin. Say this is your location.
Rotate everything by view origin's negative longitude through z-axis.
Rotate everything by view origin's negative latitude through y-axis.
At this point, the cartesian coordinate of all the points should have view location as the origin. Essentially, you are looking downward to the view origin.
Finally, scale it down and translate so that (x,y) fits in your coordinate system.

Get the MKMapView boundary in meters

How can I find out the size of the currently displayed area of MKMapKit view, ideally in meters?
MKMapKit has a visibleMapRect method which can be used to obtain a MKMapSize, for which the docs say:
The units of this value are map points.
What is a "map point"?
This might help:
iphone -- convert MKMapPoint distances to meters

Given a latitude, longitude and heading, how can I determine the lat/lon that is x meters from that point?

I have a series of lat/lon which represents the center of some object. I need to draw a line through this point that is x meters on either side of the center and it needs to be perpendicular to the heading (imagine a capital T)
Ultimately I want to get the lat/lon of this line's endpoints.
Thanks!
The basic calculation is in this similar question's answer: Calculate second point knowing the starting point and distance. Calculate the points for the two headings perpendicular to the main heading the distance away you want.
Have a look at: Core Location extensions for bearing and distance
With those extensions and two points on the initial line you should be able to get the bearing, add/subtract pi/2 and find points to either side like this:
double bearing = [bottomOfT bearingInRadiansTowardsLocation:topOfT];
CLLocation *left = [topOfT newLocationAtDistance:meters
alongBearingradians:bearing+M_PI/2];
CLLocation *right = [topOfT newLocationAtDistance:meters
alongBearingradians:bearing-M_PI/2];

Resources