Voloda2
Voloda2

Reputation: 12597

I need to figure out visible coordinates on map. Please, check me

I need to figure out visible coordinates on map. Please, check me.

CLLocationDegrees leftDegrees = mapView.region.center.longitude - (mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees rightdegrees = mapView.region.center.longitude + (mapView.region.span.longitudeDelta / 2.0);

CLLocationDegrees bottomDegrees = mapView.region.center.latitude - (mapView.region.span.latitudeDelta / 2.0);
CLLocationDegrees topDegrees = mapView.region.center.latitude + (mapView.region.span.latitudeDelta / 2.0);

if (leftDegrees > rightdegrees)
{
    [self getAnnotationFromServer: mapView.region.center andLeftDegrees:leftDegrees andRightDegrees:180 andBottomDegrees:bottomDegrees andTopDegrees:topDegrees];
    [self getAnnotationFromServer: mapView.region.center andLeftDegrees:rightdegrees andRightDegrees:-180 andBottomDegrees:bottomDegrees andTopDegrees:topDegrees];
}
else 
{
    [self getAnnotationFromServer: mapView.region.center andLeftDegrees:leftDegrees andRightDegrees:rightdegrees andBottomDegrees:bottomDegrees andTopDegrees:topDegrees];      
}

Upvotes: 0

Views: 158

Answers (1)

Ludovic Landry
Ludovic Landry

Reputation: 11774

Your code looks good, but an easy way to get annotations only for the visible part would be directly send the center and the radius to the server. you just have to choose a radius a little bigger than the screen diagonal (latitudeDelta or longitudeDelta) that you multiply by a constant.

This will also help the server because you can easely find functions tu compute distance between points and don't have to take care about the 180/-180 junction.

Upvotes: 1

Related Questions