NAMapKit
NAMapKit copied to clipboard
Convert lat/long to image coordinates
Automatically translate from real lat/long co-ordinates to the map image. I've got the MKCoordinateRegion that my image represents, so by using that it should be able to convert the points for me. Again, this will let me use my existing MKAnnotations.
Some quick n dirty code to convert CLLocationCoordinate2D coordinate
to a map image covering MKCoordinateRegion mapRegion
with dimensions CGSize mapSize
:
float minLon = mapRegion.center.longitude - (mapRegion.span.longitudeDelta / 2);
float minLat = mapRegion.center.latitude - (mapRegion.span.latitudeDelta / 2);
float x = ((coordinate.longitude - minLon) / mapRegion.span.longitudeDelta) * mapSize.width;
float y = (1.0 - ((coordinate.latitude - minLat) / mapRegion.span.latitudeDelta)) * mapSize.height;
NAAnnotation *anno = [NAAnnotation annotationWithPoint:CGPointMake(x, y)];
We get this part of the plan in https://github.com/neilang/NAMapKit/issues/13.
I take what I said above back.
Each map is its own thing, it could be a map that represents the world, but also a map that represents an indoor space. So the coordinate system of the map is specific to the scenario. So the map is a 2D image and points are either in some kind of absolute system on that image or a relative one in, say, %. There's a helper in https://github.com/neilang/NAMapKit/blob/version-3.0/NAMapKit/NATiledImageMapView.m#L106 that takes %, but that's too specific and shouldn't even be there.
I think we should design and implement a clean interface for coordinate conversion where the one given by @nicked above is an example.
Thoughts?