- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在开发 AS3 AIR for Android 应用程序。“我的问题是:给定一个 GPS 位置,我想检索运动方向(北、西北、西、西南、南、东南、东、东北)”
我想要有关如何使用 2 个不同的 GPS 读数来推断行进方向的代码。然后我想 360 度使用该数据。
我想我了解如何获得大致方向,如北、南、东和西。我会得到 2 个独立的 GPS 读数并比较类似这样的东西......
查看第一个或第二个 GPS 读数中的 X 是否更大。查看第一个或第二个 GPS 读数中的 Y 是否更大。从这里我应该能看到大方向。将 X1 和 X2 的差异与 Y1 和 Y2 的差异进行比较。然后你可以看到用户最常去的方向。然后显示方向。
我不确定如何获取数据并将其用于像指南针一样的 360 度解释...有人可以帮忙吗?
工作代码-------------------------------------------- ----------------------------------
package
{
import flash.display.Sprite;
// Geolocation sensor stuff
import flash.sensors.Geolocation;
import flash.events.GeolocationEvent;
//Timer setup stuff for setting frequesncy of GPS Update
import flash.utils.Timer;
import flash.events.TimerEvent;
// Sprite and Textfield display
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class FlashTest extends Sprite
{
//Variable to check if current or prior Geolocation Event fired
private var gpsCheck:int = 1;
public var dLon:Number
//latitude and longitude in degrees (RAW info from Geolocation)
public var gpsLat1:Number
public var gpsLon1:Number
private var gpsLat2:Number
private var gpsLon2:Number
public var bearing:Number
// Latitude and longitude in radians converted from Degrees
public var gpsLat1R:Number
public var gpsLon1R:Number
private var gpsLat2R:Number
private var gpsLon2R:Number
private var yy:Number
private var xx:Number
public function FlashTest()
{
// Text box for displaying results
var my_txt:TextField = new TextField();
my_txt.wordWrap=true;
my_txt.width = 300;
my_txt.height = 300;
addChild(my_txt);
/*
//If GPS is on device create Geolocation object named "my_geo"
//Request updates from my_geo every 2000 milliseconds. Run onGeoUpdate function
//when Event is triggered. After that create the text box for displaying data.
if (Geolocation.isSupported)
{
var my_geo:Geolocation = new Geolocation();
my_geo.setRequestedUpdateInterval(2000);
my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
var my_txt:TextField = new TextField();
my_txt.wordWrap=true;
my_txt.width = 300;
my_txt.height = 300;
addChild(my_txt);
}
// If GPS is not supported on device display "No GPS Signal"
else
{
addChild(my_txt);
my_txt.wordWrap=true;
my_txt.width = 300;
my_txt.height = 300;
addChild(my_txt);
my_txt.text = "No GPS Signal ";
}
*/
// False GPS reading being passed for testing
//COMMENT THESE LINES OUT STARTING HERE---
gpsLat1 = 42.1234584;
gpsLon1 = -83.1234577;
gpsLat2 = 42.1234583;
gpsLon2 = -83.1234577;
// END OF WHAT SHOULD BE COMMENTED OUT---
// Equations to convert all RAW Geolocation information over to radians
gpsLat1R = gpsLat1 * Math.PI / 180;
gpsLon1R = gpsLon1 * Math.PI / 180;
gpsLat2R = gpsLat2 * Math.PI / 180;
gpsLon2R = gpsLon2 * Math.PI / 180;
// The rest of the math
dLon = gpsLon1 - gpsLon2;
yy = Math.sin(dLon) * Math.cos(gpsLat2R);
xx = Math.cos(gpsLat1R) * Math.sin(gpsLat2R) - Math.sin(gpsLat1R) * Math.cos(gpsLat2R) * Math.cos(dLon);
bearing = Math.atan2(yy, xx) * 180 / Math.PI;
// Run The Geoupdate function
onGeoUpdate();
// onGeoUpdate basically displays the information that was collected and converted.
// This is where you will put what you want the code to do with the results
function onGeoUpdate():void
{
my_txt.text = "My Latitude is "+gpsLat1+ " and my Longitude is "+gpsLon1+
"My 2nd Latitude is "+gpsLat2+" and my 2nd Longitude is "+gpsLon2+
" Bearing is " +bearing;
}
}
}
}
最佳答案
你需要的公式(对于lon1
,lon2
经度,和lat1
,lat2
纬度的两个points) 在许多地方给出 - 例如,在 http://www.movable-type.co.uk/scripts/latlong.html .数学是这样的(将其转换为您最喜欢的语言...):
dLon = lon2 - lon1;
y = sin(dLon) * cos(lat2);
x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) *cos(dLon);
bearing = atan2(y, x) * 180 / Pi;
注意:atan2
将结果缩减为 [-pi, pi] 之间的值。乘以 180/pi
后,数字将介于 [-180,180] 之间。为了获得 0 到 360 之间的值,您可以这样做,例如:
if (bearing < 0) bearing += 360;
我希望您可以填写您需要的任何其他详细信息,以便为您完成这项工作。
编辑 我已经使用您提供的数字编写了一些代码:这是 Matlab,但它应该非常易读:
% bearings
lat1 = 42.1234584;
lat2 = 42.1234583;
lon1 = -83.1234577;
lon2 = -83.1234510;
% convert to radians:
g2r = pi/180;
lat1r = lat1 * g2r;
lat2r = lat2 * g2r;
lon1r = lon1 * g2r;
lon2r = lon2 * g2r;
dlonr = lon2r - lon1r;
y = sin(dlonr) * cos(lat2r);
x = cos(lat1r)*sin(lat2r) - sin(lat1r) * cos(lat2r)*cos(dlonr);
% compute bearning and convert back to degrees:
bearing = atan2(y, x) / g2r;
fprintf(1,'x: %+.3e\ny: %+.3e\nbearing: %.3f\n', x, y, bearing);
这导致输出:
x: -1.745e-09
y: +8.673e-08
bearing: 91.153
如您所见,x
和 y
很小 - 它们代表您移动的“地球周长的一部分”(大约正东 3.5 米,这似乎...)。您应该能够使用这些数字调试您的实现。
请注意,GPS 的“绝对”精度可能较差(在您的情况下,不确定性 > 100 m),但“相对”精度仍然不错(它测量两个位置之间的差异远优于 100米)。
关于android - 如何仅通过 GPS 读数确定方向并以 360 度显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18520620/
我正在使用 Selenium Web 驱动程序 3.0,并且想要从打开的两个对话框(一个在后台,第二个在前台)的 Activity 对话框中单击“确定”按钮。如何从 html 下面的父 div 单击前
actions: [ FlatButton( onPressed: () {
我有一个问题有点超出我的范围(我真的很高兴我是 Beta)涉及重复项(所以 GROUP BY, HAVING, COUNT),通过将解决方案保留在 SQLite 附带的标准函数中而变得更加复杂。我正在
使用DBI是否可以确定SELECT语句的已执行语句句柄是否返回任何行而不从中获取行? IE。就像是: use DBI; ... my $sth = $dbh->prepare("SELECT ..."
是否可以为“确定”和“关闭”按钮指定回调函数? 如果是JQuery Modal,则可以在初始化时使用按钮字典指定回调函数。 Semantic-ui模态是否提供类似的功能?按下确定后,我该如何寻求其他逻
我想阅读警报中的消息。 示例:如果警报显示“错误的电子邮件地址”。怎么读呢?意味着我想将该消息存储在字符串中。 如何在“警报”中单击“确定”...?? 如何使用 Selenium 来做到这一点? 最佳
我有一个删除按钮: 我试图首先查明是否已选择一个网站,如果已选择一个网站,我需要确定是否已选择一个或多个列表项,如果是,则继续删除这些项目。 我的 if 语句不断返回“您必须首先选择您的列表”,即使它
部分出于好奇——我们想知道在我们的应用程序中发生了什么——部分是因为我们需要在我们的代码中找到一些潜在的问题,我喜欢在我们的网络应用程序运行时跟踪一些一般值。这尤其包括某些对象图的分配内存。 我们的应
我将 SweetAlert 与 Symfony 结合使用,我希望用户在完成删除操作之前进行确认。 发生的情况是,当用户单击删除按钮时,SweetAlert 会弹出,然后立即消失,并且该项目被删除。 在
我们有一个应用程序可以生成不包括字母 O 的随机基数 35 [0-9A-Z]。我正在寻找一种解决方案来查找包含任何淫秽英语单词的代码,而无需搜索包含 10,000 个条目的列表每个生成的代码。每秒生成
这是我做的: #include #include int betweenArray(int a, int b){ int *arr,i,range; range = b - a +
我知道如何创建 警报和确认框,但我不知道如何做的是实际单击“确定”。我有一个弹出确认框的页面。 我想使用 Java Script 插件单击“确定”。基本上,我希望我的代码单击页面上的链接,然后在出现提
代码: swal('Your ORDER has been placed Successfully!!!'); window.location="index.php"; 甜蜜警报工
>>> import re >>> s = "These are the words in a sentence" >>> regex = re.compile('are|words') >>> [m
使用确定的理想散列函数给出随机期望线性时间算法两个数组 A[1..n] 和 B[1..n] 是否不相交,即 A 的元素是否也是 B 的元素。 谁能告诉我如何做到这一点,甚至如何开始考虑它? 最佳答案
我在计算机科学课上有这段代码: int input=15; while (input < n ) { input = input *3;} 这段代码有 log3(n/15) 次循环的上限。我们怎样才能
我有一个允许 2 位玩家玩 TicTacToe 的程序。在每个玩家移动之后,它应该在那个点显示棋盘并返回一个名为 Status 的枚举,显示玩家是否应该继续,如果玩家赢了,还是平局。但是,该算法要么返
给定一个 y 值数组,例如 [-3400, -1000, 500, 1200, 3790],我如何确定“好的”Y 轴标签并将它们放置在网格上? ^ ---(6,000)-|---
假设我有一个检查用户登录的 SQL 语句: SELECT * FROM users WHERE username='test@example.com', password='abc123', expi
teradata中有返回表中哪一列被定义为主索引的命令吗?我没有制作一些我正在处理的表,也没有尝试优化我对这些表的连接。谢谢! 最佳答案 有dbc.IndicesV,其中IndexNumber=1表示
我是一名优秀的程序员,十分优秀!