tags:

views:

262

answers:

1

MapKit use mercator projection, how i can convert latitude to Y screen coordinate? Update: Thanks. i use it

CLLocationCoordinate2D leftTopBoxCoordinate;
leftTopBoxCoordinate.longitude=-180+cacheRegion.minX*boxSize;
leftTopBoxCoordinate.latitude=85-cacheRegion.minY*boxSize;
CGPoint leftTopPoint = [map convertCoordinate:leftTopBoxCoordinate toPointToView:map];

int boxDY=leftTopPoint.y;
int boxDX=leftTopPoint.x;
NSLog(@"\nL:%f,G:%f\nDX:%d,DY:%d\n",topLeft.latitude,topLeft.longitude,boxDX,boxDY);

I need to draw grid that bind to map, cacheRegion.minY - is minimal index of box in grid, by this i calculate latitude and longitude of box and i need to calculate destance between leftop box and mapview region. But after 10 degree [map convertCoordinate:leftTopBoxCoordinate toPointToView:map]; not work. This good

-[GridOverlay drawRect:]: 
L:80.058050,G:-180.000000
DX:0,DY:-56
This bad
-[GridOverlay drawRect:]: 
L:79.432371,G:-180.000000
DX:0,DY:28

All Log:

-[GridOverlay drawRect:]: 
L:85.000000,G:-180.000000
DX:0,DY:0
-[GridOverlay drawRect:]: 
L:80.058050,G:-180.000000
DX:0,DY:-56
-[GridOverlay drawRect:]: 
L:79.432371,G:-180.000000
DX:0,DY:28

What's happend? do you know?i

A: 

Mercator projection maps latitude linearly, so you could calculate the coordinate from the map view’s region property.

However, MKMapView has a method that maps coordinates from WGS84 to screen: convertCoordinate:toPointToView:.

Nikolai Ruhe
please see my update.
Sergey Zenchenko