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

十年热恋 提交于 2019-12-11 10:08:56

问题


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 latitudeDelta 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


回答1:


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


来源:https://stackoverflow.com/questions/2727844/what-is-the-difference-between-latitude-longitude-and-their-delat-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!