NAMapKit icon indicating copy to clipboard operation
NAMapKit copied to clipboard

Convert lat/long to image coordinates

Open nicked opened this issue 12 years ago • 3 comments

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.

nicked avatar Oct 09 '12 12:10 nicked

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)];

nicked avatar Oct 09 '12 13:10 nicked

We get this part of the plan in https://github.com/neilang/NAMapKit/issues/13.

dblock avatar Mar 05 '14 15:03 dblock

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?

dblock avatar Mar 14 '14 22:03 dblock