开发者

what is the difference between latitude, longitude and their delat values

I'm new to the MKMapView (iPhone). I want to add several annotations to the map of Copenhagen (Denmark). I have the latitude and longitude values of different locations of the city. But I don't know how to get the longitudeDelta and latitude开发者_如何学编程Delta of these locations. I'm using the Google Map API's to calculate the latitude and longitude values (By web services) of each location in the city map. I need help on how to calculate delta values

Thanks


I'm not certain from your question what purpose you are looking to calculate lat and long deltas, but the only reference I have seen int he MKMapView is in the specification of the MKCoordinateSpan to establish the zoom level of the MapView to display.

I found this code on the Net somewhere that will take a MapView with annotations added to the annotation layer, and calculate and set the region to display to make all annotations visible in the MapView. Perhaps this will help

CLLocationCoordinate2D topLeftCoord;
topLeftCoord.latitude = -90;
topLeftCoord.longitude = 180;

CLLocationCoordinate2D bottomRightCoord;
bottomRightCoord.latitude = 90;
bottomRightCoord.longitude = -180;

for(MKAnnotation* annotation in self.mapView.annotations)
{
    topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
    topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);

    bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
    bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
}

MKCoordinateRegion region;
region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.8; // Add a little extra space on the sides
region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.8; // Add a little extra space on the sides

region = [self.mapView regionThatFits:region];
[self.mapView setRegion:region animated:NO];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜