基于位置的警报-Android应用程序 [英] Location based Alarm - An Android application

查看:77
本文介绍了基于位置的警报-Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个android应用程序,用户可以在其中使用经度和纬度保存所需的位置.当用户靠近该位置时,警报会响起.

已经开发了用于检索当前位置甚至通过地理编码获得所需位置的代码.并在数据库中保存经度,纬度,标题和位置描述.

现在,当比较时,当保存的位置与当前位置匹配时,现在还不知道如何编码,发出警报并显示相关信息.

请帮助.

预先谢谢您.

I''m developing a android application where user can save his required locations using latitude and longitude. A alarm should ring when user is near to that location.

Have developed the code for retrieving current location and even getting required location through geocoding. And Saved the longitude,latitude, title and description of location in a database.

Now not getting how to code , to ring a alarm and display related information when saved location matches with current location while comparing.

Plzz help.

Thank you in advance.

推荐答案

您要做的就是为存储在数据集中的每个位置定义一个接近半径.然后计算当前坐标(纬度,经度)当前与存储的坐标(纬度,经度)已存储之间的距离,以找出实际距离.如果实际距离小于或等于接近半径,则必须发出警报.

如果不确定如何计算两对坐标之间的距离,请参见:计算距离,方位等纬度/经度点之间 [^ ].


All you have to do is define a proximity radius for each of the locations you stored in your data set. And then do a calculation of the distance between the current coordinates (latitude,longitude)current and the store coordinates (latitude,longitude)stored to find out the actual distance. If the actual distance is smaller or equal to the proximity radius you''ll have to sound the alarm.

If you are unsure how to calculate the distance between two pairs of coordinates, see here: Calculate distance, bearing and more between Latitude/Longitude points[^].


var R = 6371; // earth's radius in kilometers (km)

var dLat = (lat2-lat1).toRad(); // Conversion to radians can also be achieved by lat1 * Math.PI / 180
var dLon = (lon2-lon1).toRad(); // Conversion to radians can also be achieved by lat1 * Math.PI / 180

var lat1 = lat1.toRad(); // Conversion to radians can also be achieved by lat1 * Math.PI / 180
var lat2 = lat2.toRad(); // Conversion to radians can also be achieved by lat2 * Math.PI / 180

var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // This now holds the distance expressed in km



[/编辑]

还有问题吗?

问候,

曼弗雷德(Manfred)



[/Edit]

Any questions left?

Regards,

Manfred


这篇关于基于位置的警报-Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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