- 浏览: 569807 次
- 来自: -
-
博客专栏
-
-
libgdx 游戏开发
浏览量:12419
文章分类
- 全部博客 (171)
- OS (1)
- JavaScript (13)
- Struts (2)
- Regular Expression (1)
- Java (14)
- HTML (4)
- XML (1)
- Non-Relational Database (2)
- Miscellaneous (7)
- Lotus Notes (8)
- Algorithm (3)
- Web Analytics (6)
- Web (8)
- Perl (3)
- PHP (3)
- C & C++ (1)
- Shell (7)
- Google (1)
- Android (31)
- iPhone (1)
- SQL (1)
- HTML5 (3)
- jQuery (5)
- CSS (6)
- PostgreSQL (1)
- Design Patterns (1)
- Excel (1)
- Magento (4)
- jMeter (3)
- SEO (1)
- libgdx (5)
- Software (3)
- App (1)
- Game (1)
- Gradle (1)
- Linux (15)
- Ubuntu (4)
- Docker (2)
- Spring (2)
- Other (2)
- Directory Server (1)
- CentOS (1)
- Python (1)
- VCS (3)
- Database (1)
- Open Source (1)
最新评论
-
ls0609:
赞一个,支持下博主。
[原创] Android ListView 在右上角添加三角形图标和文字 -
love297:
不让别人商用,自己先商用起来了。
手机游戏开发展示 -
a851206:
你的有些类是哪里来的?我想研究一下你的程序,可是有些类没有代码 ...
[原创] Google Custom Search & Yahoo Boss Search | Web Search API 使用 -
ypppk:
BitmapFactory.Options options = ...
[原创] 连载 1 - 深入讨论 Android 关于高效显示图片的问题 - 如何高效的加载大位图 -
笑遍世界:
我也遇到了,弄清了其中原因,可参考我的博客:http://sm ...
[原创] 使用 jMeter 登录 Wordpress
最近在做Android手机应用开发,还是很有意思的。其实如果只是做简单手机应用开发而不是手机游戏开发的话,还是很简单的。把主要的控件掌握了,就可以开发简单的应用了。
下面主要说一下在Android中使用GPS功能。
开发由于GPS功能时,常与Google Map相关,因此先推荐一篇讲解Google Map的文章:
http://mobiforge.com/developing/story/using-google-maps-android
该文章详细的讲解了Android中如何使用Google Map的各种功能。文章甚好,强烈推荐。
看完了如上文章后,我们就来讲解下如何使用GPS。
首先在AndroidManifest.xml中添加位置服务权限:
然后再看如下代码例:
先注册LocationManager,然后就可以通过访问getLastKnownLocation得到当前的GPS坐标。是不是很简单。
既然是GPS,我们当然不只是想知道当前的位置,更重要的是要随着位置的移动,GPS信息也要更新。那么我们需要怎么做呢?
还先看如下代码例:
声明自己的LocationListener后,调用requestLocationUpdates方法,就可以得到最新的GPS信息。
常用方法说明:
public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener)
当时间超过minTime(单位:毫秒),或者位置移动超过minDistance(单位:米),就会调用listener中的方法更新GPS信息。
官方文档中有如下说明:
1. minTime的值最好是不小于60000(即:1分钟),这样会更加高效且节电。
2. 如果要尽可能实时的更新GPS信息,请将minTime和minDistance都设置成0。
以说明下来自官方文档:
Registers the current activity to be notified periodically by the named provider. Periodically, the supplied LocationListener will be called with the current Location or with status updates.
It may take a while to receive the most recent location. If an immediate location is required, applications may use the getLastKnownLocation(String) method.
In case the provider is disabled by the user, updates will stop, and the onProviderDisabled(String) method will be called. As soon as the provider is enabled again, the onProviderEnabled(String) method will be called and location updates will start again.
The frequency of notification may be controlled using the minTime and minDistance parameters. If minTime is greater than 0, the LocationManager could potentially rest for minTime milliseconds between location updates to conserve power. If minDistance is greater than 0, a location will only be broadcasted if the device moves by minDistance meters. To obtain notifications as frequently as possible, set both parameters to 0.
Background services should be careful about setting a sufficiently high minTime so that the device doesn't consume too much power by keeping the GPS or wireless radios on all the time. In particular, values under 60000ms are not recommended.
The calling thread must be a Looper thread such as the main thread of the calling Activity.
下面主要说一下在Android中使用GPS功能。
开发由于GPS功能时,常与Google Map相关,因此先推荐一篇讲解Google Map的文章:
http://mobiforge.com/developing/story/using-google-maps-android
该文章详细的讲解了Android中如何使用Google Map的各种功能。文章甚好,强烈推荐。
看完了如上文章后,我们就来讲解下如何使用GPS。
首先在AndroidManifest.xml中添加位置服务权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
然后再看如下代码例:
LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location loc = locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (loc != null) { lat = loc.getLatitude(); Log.d(TAG, "latitude: " + lat); lng = loc.getLongitude(); Log.d(TAG, "longitude: " + lng); }
先注册LocationManager,然后就可以通过访问getLastKnownLocation得到当前的GPS坐标。是不是很简单。
既然是GPS,我们当然不只是想知道当前的位置,更重要的是要随着位置的移动,GPS信息也要更新。那么我们需要怎么做呢?
还先看如下代码例:
LocationListener locLis = new MyLocationListener(); locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 10, locLis); ... ... ... public class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc) { if (loc != null) { p = new GeoPoint((int) (loc.getLatitude() * 1E6), (int) (loc.getLongitude() * 1E6)); mc.animateTo(p); mc.setZoom(14); mc.setCenter(p); } } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }
声明自己的LocationListener后,调用requestLocationUpdates方法,就可以得到最新的GPS信息。
常用方法说明:
public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener)
当时间超过minTime(单位:毫秒),或者位置移动超过minDistance(单位:米),就会调用listener中的方法更新GPS信息。
官方文档中有如下说明:
1. minTime的值最好是不小于60000(即:1分钟),这样会更加高效且节电。
2. 如果要尽可能实时的更新GPS信息,请将minTime和minDistance都设置成0。
以说明下来自官方文档:
Registers the current activity to be notified periodically by the named provider. Periodically, the supplied LocationListener will be called with the current Location or with status updates.
It may take a while to receive the most recent location. If an immediate location is required, applications may use the getLastKnownLocation(String) method.
In case the provider is disabled by the user, updates will stop, and the onProviderDisabled(String) method will be called. As soon as the provider is enabled again, the onProviderEnabled(String) method will be called and location updates will start again.
The frequency of notification may be controlled using the minTime and minDistance parameters. If minTime is greater than 0, the LocationManager could potentially rest for minTime milliseconds between location updates to conserve power. If minDistance is greater than 0, a location will only be broadcasted if the device moves by minDistance meters. To obtain notifications as frequently as possible, set both parameters to 0.
Background services should be careful about setting a sufficiently high minTime so that the device doesn't consume too much power by keeping the GPS or wireless radios on all the time. In particular, values under 60000ms are not recommended.
The calling thread must be a Looper thread such as the main thread of the calling Activity.
发表评论
-
[转] DialogFragment Fragment already added
2017-10-25 11:16 2861原文地址:http://blog.csdn.net/u0129 ... -
Android Studio .gitignore
2017-10-16 15:44 961参考文献: https://github.com/github ... -
[转] How to detect incoming calls in an Android
2017-10-13 14:14 1291原文地址:https://stackoverflow.com/ ... -
[转] Android 检测电源按钮是否被按下
2017-10-11 12:55 1132原文地址:https://stackoverflow.com/ ... -
[原创] Android Activity onNewIntent() 详解
2017-08-16 13:46 4881阅读难度:中 阅读前提: 1. 需要了解 Android 的生 ... -
[转] Android Webview: “Uncaught TypeError: Cannot read property 'getItem' of null
2017-08-14 15:09 2453原文地址:https://stackoverflow.com/ ... -
[原创] 使用 Vitamio 播放视频作为 Splash 时出现失真情况的解决方案
2017-08-02 09:10 1265目前在做关于视频及流媒体播放项目时,有这样一个需求,应用启动时 ... -
[转] Android: Expand/collapse animation
2017-07-31 14:57 1625原文地址:https://stackoverflow.com/ ... -
[原创] Android ListView 在右上角添加三角形图标和文字
2017-07-26 17:24 2841最终显示效果如下图,在右上角添加三角形图标并在图标内显示文字: ... -
[转] Detect home button press in android
2017-07-20 17:49 1214原文地址:https://stackoverflow.com/ ... -
[原创] 开启 Android TextView Marquee
2017-07-18 15:47 1858亲测可能。直接上代码。 测试机器:XiaoMi 2S Andr ... -
[原创] 小米手机无法真机调试
2017-07-06 09:10 6553系统环境: 小米 2S MIUI 版本:8.0.1.0(LXA ... -
了解数据绑定 - Data Binding Library
2017-06-22 15:31 1056原文地址: -
How to play gif with Fresco
2017-06-22 14:00 740原文地址:https://stackoverflow.com/ ... -
设置 Toolbar(ActionBar) 上的按钮颜色
2017-06-22 08:11 2123原文地址: https://stackoverflow.com ... -
Display back button on action bar and back event
2017-06-22 08:00 794原文地址: https://stackoverflow.com ... -
Gradle 修改 Maven 仓库地址
2017-06-02 15:51 1734修改 Gradle Maven 仓库地址为阿里云镜像 修改根 ... -
[转] How to clear cookies and cache of webview on Android when not in webview?
2017-04-26 09:28 2240原文地址:http://stackoverflow.com/a ... -
[转] Android 在程序中如何动态的修改程序图标
2017-03-02 17:05 1011http://stackoverflow.com/a/4150 ... -
[转] Android Libraries
2017-01-16 10:28 600原文地址: https://dzone.com/article ...
相关推荐
"有侦测卫星数量及信号等等"意味着该应用不仅能够获取用户的位置信息,还能显示当前连接到设备的GPS卫星数量以及它们的信号强度,这对于评估定位精度和诊断GPS问题非常有用。 【标签】"android" 指出这个项目是基于...
2. **位置服务(LBS)**:讨论了如何利用地理位置信息为用户提供定制化服务,包括获取用户位置、搜索附近餐厅及路径规划。 3. **服务器端开发**:可能涉及到ASP.NET技术,用于构建后台管理系统,发布和管理餐饮信息...
4:GPS定位:该子系统能获取旅游者当前所在的位置信息,能对设定的区域在进入或离开时予以音乐提醒,能将旅游者所走过的路径、平均速度等信息保存至数据库,供随时查看并动画回放。 ——————————————...
定位导航模块:定位导航模块分为用户位置实时定位和停车路线实时导航,基于百度地图API和GPS技术为用户提供当前位置到停车位路径导航。 出租预约车位模块:车位主在App上出租自己的车位,并提供车位的相关信息、地址...
在设计和开发这款天气预报系统时,开发者可能利用了Android提供的定位服务,以便确定用户位置并推荐当地的天气信息。同时,系统可能集成了第三方天气API,如OpenWeatherMap或AccuWeather,以获取实时的气象数据。 ...