Android Google Map实例 - 获取cdma基站经纬度(Android mapview)

来源:互联网 发布:mac虚拟机win7激活码 编辑:程序博客网 时间:2024/05/16 10:04

已经将GPS信息标注在google map上了,怎么将目前正在提供服务的基站位置也标注在google map上呢?

  标注的方法与标注自定义图标一样,关键是如何获取cdma cell location,为这个问题困扰了好几天,有人说利用google gears方法,不过这种方法原理是取得目前通讯的基站信息譬如cid nid等,上网查询并反馈对应的基站经纬度,需要对应的网站有足够的基站经纬度信息。

 

  对于CDMA手机其实有更方便的方法,就是利用CdmaCellLocation.getBaseStationLatitude(),但是getBaseStationLatitude()获取的是int值的纬度,在android doc里也没有详细的阐述。国外的论坛也有人说getBaseStationLatitude()返回的是垃圾信息,昨天google到一个泡菜国兄弟的帖子才找到getBaseStationLatitude()获取的是int值与真正经纬度之间的关系。

 

  也就是CDMA层3协议的定义:

    /** 
     * Latitude is a decimal number asspecified in 3GPP2 C.S0005-A v6.0.
     * It is represented in units of 0.25seconds and ranges from -1296000
     * to 1296000, both values inclusive(corresponding to a range of -90
     * to +90 degrees). Integer.MAX_VALUEis considered invalid value.
     */

  /**

     * Longitude is a decimal number asspecified in 3GPP2 C.S0005-A v6.0.
     * It is represented in units of 0.25seconds and ranges from -2592000
     * to 2592000, both values inclusive(corresponding to a range of -180
     * to +180 degrees).Integer.MAX_VALUE is considered invalid value.
     */

因此只要将getBaseStationLatitude()做如下处理即可:

double lat = (double)myCDMACellLoc.getBaseStationLatitude()  /14400;
double lon = (double)myCDMACellLoc.getBaseStationLongitude() /14400;

/14400即  *90/1296000

这样问题就解决了!!!

关键代码:

 

[c-sharp] view plaincopy
  1. telephonyManager =(TelephonyManager)getSystemService(TELEPHONY_SERVICE);  
  2. myCDMACellLoc = (CdmaCellLocation)telephonyManager.getCellLocation();  
  3. double lat = (double)myCDMACellLoc.getBaseStationLatitude()  /14400;  
  4. double lon = (double)myCDMACellLoc.getBaseStationLongitude() /14400;  
 

Android Google Map实例 - 不同的图标标注在同一图层(Android mapview)

Android Google Map实例 - 添加GPS位置标注(Android mapview)