使用当前位置和目的地位置的经度和纬度,我们如何才能在iphone中获得方向 [英] Using lattitude and longitude of the current location and destination location , how can we get the direction in iphone

查看:91
本文介绍了使用当前位置和目的地位置的经度和纬度,我们如何才能在iphone中获得方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在1 iphone应用程序中工作,我们需要显示从1个地方到另一个地方的方向
从当前位置向哪个方向(N或E或W或S或NE或NW或SE或SW)的目的地是。
我知道如何获得从一个地方到另一个地方的方向,但我正在寻找显示方向。
我的问题清楚了吗?如果有人知道如何去做,Pleae帮助我
感谢每一个!

解决方案

这两个位置?



请看 CLLocationCoordinate2D


纬度
以度为单位的纬度。正值表示赤道以北的纬度。负值表示赤道以南的纬度。


经度
以度为单位的经度。测量是相对于零子午线的,正值延伸到子午线以东,负值延伸到子午线以西。

纬度是因此很简单,如果目的地的纬度小于当前位置的纬度,那么它位于北方,如果它大于当前位置的纬度,那么它位于南方。



latitudinal_distance = destination.latitude - origin.latitude



经度稍微复杂一点,因为您应该考虑在东边的地球四分之三的地方可能更好地表达为西方。再次比较经度值,考虑东西方距离,处理穿越子午线,选择较短距离。

distance_east =(原点.longitude> 0&& destination.longitude< 0)? 180 - origin.longitude + destination.longitude - -180:destination.longitude - origin.longitude; if(distance_east <0)distance_east + = 360

distance_west =(origin.longitude <0& & destination.longitude> 0)? -180 - origin.longitude - 180 - destination.longitude:origin.longitude - destination.longitude; if(distance_west <0)distance_west + = 360



longitudinal_distance = min(distance_east,distance_west) $ b

一旦你知道有多少度的经度和纬度将你的两点分开,你可以计算一个到目的地的标题,并决定哪个标题应该显示为指南针点。在只有四个点(N,E,S,W)的指南针上,每个点将覆盖90度。在一个8点的指南针上,每个点将覆盖45度。



heading = arctan(longitudinal_distance / latitudinal_distance)
<$ c $如果(标题> = -45 ||标题< 45)返回'N';否则如果(标题> = 45&<标题< 135)返回'E';如果...



这里已经很晚了,我没有测试这些表达式,所以如果它们看起来有用,请确保您理解并测试而不是试图盲目应用它们。不幸的是,我调换了一个符号或坐标对的几率很高。

I am working in 1 iphone app where we need to show the direction from 1 place to other place That is from current location in which direction (N or E or W or S or NE or NW or SE or SW ) the destination is . I know how to get the directions from 1 place to another place but I am searching for showing the direction . Is my problem clear ? If any one know how to do it , Pleae help me Thanks every one!

解决方案

Do you know the coordinates of the two locations?

Look at CLLocationCoordinate2D:

latitude The latitude in degrees. Positive values indicate latitudes north of the equator. Negative values indicate latitudes south of the equator.

longitude The longitude in degrees. Measurements are relative to the zero meridian, with positive values extending east of the meridian and negative values extending west of the meridian.

Latitude is therefore quite simple, if the destination's latitude is less than the current location's latitude then it lies to the north, if it is greater than the current location's latitude then it lies to the south.

latitudinal_distance = destination.latitude - origin.latitude

Longitude is slightly more complex as you should consider that a destination three quarters of the way around the Earth to the east is probably better expressed as being to the west. Again compare the longitude values, consider the distance both east and west, handle crossing the meridian, and choose the shorter distance.

distance_east = (origin.longitude > 0 && destination.longitude < 0) ? 180 - origin.longitude + destination.longitude - -180 : destination.longitude - origin.longitude; if (distance_east < 0) distance_east += 360

distance_west = (origin.longitude < 0 && destination.longitude > 0) ? -180 - origin.longitude - 180 - destination.longitude : origin.longitude - destination.longitude; if (distance_west < 0) distance_west += 360

longitudinal_distance = min(distance_east, distance_west)

Once you know how many degrees of latitude and longitude separate your two points you can calculate a heading to your destination and decide which heading should be show as which compass points. On a compass with only four points (N, E, S, W) each point would cover 90 degrees. On a compass with 8 points each point would cover 45 degrees. Hopefully you get the idea.

heading = arctan(longitudinal_distance / latitudinal_distance) if (heading >= -45 || heading < 45) return 'N'; else if (heading >= 45 && heading < 135) return 'E'; else if ...

It's late here and I'm not testing those expressions so if they seem useful please make sure you understand and test them instead of trying to apply them blindly. The odds that I transposed a sign or coordinate pair are unfortunately high.

这篇关于使用当前位置和目的地位置的经度和纬度,我们如何才能在iphone中获得方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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