android location provider有两个:
- LocationManager.GPS_PROVIDER:GPS,精度比较高,但是慢而且消耗电力,而且可能因为天气原因或者障碍物而无法获取卫星信息,另外设备可能没有GPS模块;
- LocationManager.NETWORK_PROVIDER:通过网络获取定位信息,精度低,耗电少,获取信息速度较快,不依赖GPS模块。
为了程序的通用性,希望动态选择location provider。对android通过Location API显示地址信息做了个别改动,可以看到使用了gps定位,精度较高:
android的Locatin API,可以通过Geocoder类,显示具体经纬度的地址信息。如:
使用google map api是有限制的,见:
文档的第10部分,license restrictions,详述了各种限制情况。
我比较关注的是,是否可以在自己的产品中调用google map api的导航功能,比如设置行车路线等。
这里见10.9:
10.9 use the Service or Content with any products, systems, or applications for or in connection with:
(a) real time navigation or route guidance, including but not limited to turn-by-turn route guidance that is synchronized to the position of a user’s sensor-enabled device;
(b) any systems or functions for automatic or autonomous control of vehicle behavior; or
(c) dispatch, fleet management, business asset tracking, or similar enterprise applications (the Google Maps APIs can be used to track assets (such as cars, buses or other vehicles) as long as the tracking application is made available to the public without charge. For example, you may offer a free, publicMaps API Implementation that displays real-time public transit or other transportation status information. If your Maps API Implementation is deployed internally or you are charging for use of your Maps API Implementation, please contact the Google Maps API Premier sales team for more information);
在编写最简单的android谷歌地图应用中展示的是最简单的MapView,默认显示的是世界地图。如果要切换到中国,再具体点,到北京。
百度百科上的北京经纬度是:
北纬39度54分,东经116度23分
如果近似到北纬40度,东经116度,也应该差不多。那么怎么在android的google map api中显示呢?比如这样:
上次去机房做系统。同事忘记退出tty了。
这样每次查看登录在线用户,总有个tty1挂在上面。
有可能当时根本没有退出,那谁一插显示器和键盘 … ,总是个安全隐患。直接杀进程吧。
找到tty1:
ps -ef | grep ‘tty1′
找到进程号:
user_name 23320 1 0 20:34 tty1 00:00:00 /sbin/getty -8 38400 tty1
在这里是23320,杀掉它:
sudo kill –9 23320
但是这种办法,因为linux的内部机制,tty1会在被杀掉后重生。
查了一下,有简单的办法:
sudo stop tty1
在输入:
w
清静了。
使用android的定位API,首先测试了一下粗略精度情况。即,使用网络定位,通过WIFI或者电话卡id。
可以看到比java me定位API的简单使用精度差,这里测试用的是联通卡。也测试了使用WIFI,也许因为wifi也使用了本地的联通,两个测试的经纬度坐标值是一样的。
今天安装了一下zxing条形码工具到nokia 6210ci,根本不可用。
然后找本书试试:
6210ci像素点比较低,只有二百万像素,而且不支持自动对焦,仅从手机屏幕截图来看,我都觉得识别没戏。
果然是没戏啊。
java me的JSR-179(Location API)是用于定位的。很多手机并没有GPS,因此不能精准定位。但是GPS也有问题,比较费电。
很多手机可以借助运营商的网络和基站三角定位,来获得比较粗略的定位。
在nokia 6210ci上测试了一下jsr-179的支持情况。运行效果是:
输出纬度和经度。把这段内容复制到google map的文本框中,显示的位置和我办公地点相差不到1公里。
javame收发短信,必须带端口号。
通过手机发送的短信一般都不带端口号。使用短信猫,可以发送带端口号的短信,如果不指定端口,则是-1。
短信猫发送短信,可参见使用smslib收发短信。并在此基础上增加:
msg.setSrcPort(1234);
msg.setDstPort(1234);
发送短信前需要设置端口号,这两个缺一不可。
其实主要在javame这边。
如果是javame程序正在运行,那么可以通过类似方式:
public void run() {
try {
this.connection = (MessageConnection) Connector.open("sms://:" + this.port);
while (!stop) {
try {
Message message = this.connection.receive();
在一个新线程里同步接收短信。