纬度,经度和它们的delat值有什么区别 [英] what is the difference between latitude, longitude and their delat values

查看:92
本文介绍了纬度,经度和它们的delat值有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MKMapView(iPhone)的新手.我想在哥本哈根(丹麦)地图上添加几个注释.我具有城市不同位置的经度和纬度值.但是我不知道如何获取这些位置的经度和纬度.我正在使用Google Map API来计算城市地图中每个位置的纬度和经度值(通过Web服务). 我需要有关如何计算增量值的帮助

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

谢谢

推荐答案

从您的问题中我不确定您要计算纬度和经度增量的目的是什么,但是我看到的唯一参考是MKMapView在MKCoordinateSpan的规范,以建立要显示的MapView的缩放级别.

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.

我在网上找到了此代码,该代码将带注释添加到注释层的MapView,然后计算并设置要显示的区域,以使所有注释在MapView中可见.也许这会有所帮助

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

这篇关于纬度,经度和它们的delat值有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆