为什么 getBaseStationLatitude() 不断返回 Integer.MAX_VALUE(未知)?

发布于 2024-10-26 15:04:52 字数 2354 浏览 7 评论 0原文

班级项目&论文工作 - 尝试从 CDMA 小区提取信息,特别是通过使用 getBaseStationLatitude() 和 getBaseStationLatitude() 来获取信息。 getBaseStationLongitude()。返回的值是 MAX_VALUE (2147483647) - 我没有收到实际的纬度/经度。 getBaseStationID()、getNetworkID() & getSystemID() 返回有效的 ID。我已经在两个单独的单元格中对此进行了测试,但没有成功。我的代码发布在下面。 ACCESS_FINE_LOCATION 和ACCESS_COURSE_LOCATION 添加到清单中。测试在 Droid、Android 2.2.2 上完成。

问题 - 有人遇到过同样的问题吗?我在代码中遗漏了什么吗?这些值在哪里存储和发布(例如,这些坐标是在基站分配的,并且不断传输到移动设备)?

代码:

package xXx.edu.com;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class CDMAData extends Activity implements OnClickListener{

    CdmaCellLocation location;
    int cellID, lat, lon, netID, sysID;
    private Context context;
    Button getDataBtn;

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      context = (Context) this;
      setContentView(R.layout.cid);

      setConnections();
   }

   private void setConnections() {

       getDataBtn = (Button) this.findViewById(R.id.getID);
       getDataBtn.setOnClickListener(this);

   }

   public void onClick(View v) {

       TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
       location = (CdmaCellLocation) tm.getCellLocation();
       cellID = location.getBaseStationId();
       lat = location.getBaseStationLatitude();
       lon = location.getBaseStationLongitude();
       netID = location.getNetworkId();
       sysID = location.getSystemId();

       TextView myView1 = (TextView) findViewById(R.id.bsID);
       myView1.setText("" + cellID);

       TextView myView2 = (TextView) findViewById(R.id.bsLat);
       myView2.setText("" + lat);

       TextView myView3 = (TextView) findViewById(R.id.bsLon);
       myView3.setText("" + lon);

       TextView myView4 = (TextView) findViewById(R.id.netID);
       myView4.setText("" + netID);

       TextView myView5 = (TextView) findViewById(R.id.sysID);
       myView5.setText("" + sysID);

   }
}

Class project & thesis work - trying to pull information from CDMA Cell, specifically by using the getBaseStationLatitude() & getBaseStationLongitude(). The value being returned is the MAX_VALUE (2147483647) - I'm not receiving actual lat/longs. getBaseStationID(), getNetworkID() & getSystemID() are returning valid id's. I've tested this in 2 separate cells with no luck. My code is posted below. Both ACCESS_FINE_LOCATION & ACCESS_COURSE_LOCATION are added to manifest. Testing done on Droid, Android 2.2.2.

Questions - Has anyone run into same problems? Am I missing something in the code? Where are these values stored and issued at (e.g. are these coordinates assigned at the base station, and constantly being transmitted to mobile device)?

Code:

package xXx.edu.com;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class CDMAData extends Activity implements OnClickListener{

    CdmaCellLocation location;
    int cellID, lat, lon, netID, sysID;
    private Context context;
    Button getDataBtn;

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      context = (Context) this;
      setContentView(R.layout.cid);

      setConnections();
   }

   private void setConnections() {

       getDataBtn = (Button) this.findViewById(R.id.getID);
       getDataBtn.setOnClickListener(this);

   }

   public void onClick(View v) {

       TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
       location = (CdmaCellLocation) tm.getCellLocation();
       cellID = location.getBaseStationId();
       lat = location.getBaseStationLatitude();
       lon = location.getBaseStationLongitude();
       netID = location.getNetworkId();
       sysID = location.getSystemId();

       TextView myView1 = (TextView) findViewById(R.id.bsID);
       myView1.setText("" + cellID);

       TextView myView2 = (TextView) findViewById(R.id.bsLat);
       myView2.setText("" + lat);

       TextView myView3 = (TextView) findViewById(R.id.bsLon);
       myView3.setText("" + lon);

       TextView myView4 = (TextView) findViewById(R.id.netID);
       myView4.setText("" + netID);

       TextView myView5 = (TextView) findViewById(R.id.sysID);
       myView5.setText("" + sysID);

   }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅语花开 2024-11-02 15:04:52

从 TelephonyManager 获取位置之前,尝试调用“CellLocation.requestLocationUpdate()”方法。这将强制平台更新小区位置,并且如果设备已注册到 CDMA 网络,则应为您提供有效值:

CellLocation.requestLocationUpdate();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
location = (CdmaCellLocation) tm.getCellLocation();
cellID = location.getBaseStationId();
....

此方法的文档:
http://developer.android.com/reference/android/telephony/CellLocation .html#requestLocationUpdate()

Try calling the "CellLocation.requestLocationUpdate()" method before getting the location from the TelephonyManager. This will force the platform to update the cell location and should give you a valid value if the device is registered to the CDMA network:

CellLocation.requestLocationUpdate();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
location = (CdmaCellLocation) tm.getCellLocation();
cellID = location.getBaseStationId();
....

Documentation for this method:
http://developer.android.com/reference/android/telephony/CellLocation.html#requestLocationUpdate()

终陌 2024-11-02 15:04:52

原因如下:

纬度是 3GPP2 C.S0005-A v6.0.It 中指定的十进制数
以 0.25 秒为单位表示,范围从 -1296000 到
1296000,包括两个值(对应于 -90 到 +90 的范围
度)。 Integer.MAX_VALUE 被视为无效值。

经度是 3GPP2 C.S0005-A v6.0 中指定的十进制数。它
以 0.25 秒为单位表示,范围从 -2592000 到
2592000,包括两个值(对应于 -180 到
+180 度)。 Integer.MAX_VALUE 被视为无效值。

说:

纬度 = L (Android cdma API 返回的整数)

纬度(度) = (( L * 90)/1296000))

现在您可以轻松地将其转换为度分和秒:
以下是执行此操作的 URL(以下任何链接都应该有效):
http://zonalandeducation.com/mmts/trigonometryRealms/degMinSec/degMinSec.htm

http://www.fcc.gov/mb/audio/bickel/DDDMMSS -十进制.html

Here is why:

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

Longitude is a decimal number as specified in 3GPP2 C.S0005-A v6.0. It
is represented in units of 0.25 seconds 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.

Say:

Latitude = L (integer as returned by Android cdma API)

Latitude in degree = (( L * 90)/1296000))

Now you can easily convert it to degree min and seconds:
Following is the URL to do that(any of the following links should work):
http://zonalandeducation.com/mmts/trigonometryRealms/degMinSec/degMinSec.htm

http://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html

GRAY°灰色天空 2024-11-02 15:04:52

您没有收到有效坐标的真正原因是因为某些手机提供商不提供该信息,或者他们提供了错误的信息。

我为我发布的一款应用程序对此进行了大量的个人研究。并且,尝试帮助您指明正确的方向:(以下是许多不同测试的概括,因此您可能能够找到一种不同的设备)
- T-Mobile 等 GSM 手机提供商将始终返回无效。
- Sprint 倾向于返回良好/有效的值。
- Verizon 提供的信号塔信息往往相距数英里。

ps - 如果您有兴趣,我的应用程序是 Google Play 中的 LTE Discovery。它将向您显示可以从 Android API 检索的所有不同类型的坐标。 (但是,我不会链接到它,因为它可能会反对某些广告。)

The real reason you aren't receiving valid coordinates is because some cell providers just don't provide that information, or they they provide wrong information.

I've done tons of personal research into this for one of my published apps. And, to try to help point you in the right direction: (the following are generalizations from many different tests, so you might be able to find one device that differs)
- GSM cell providers like T-Mobile will always return invalid.
- Sprint tends to return good/valid values.
- Verizon provides tower information that tends to be many miles off.

ps - Just in case you are interested, my app is LTE Discovery, in Google Play. It will show you all different types of coordinates possible to retrieve from Android API. (But, I'm not linking to it because it might be against some advertising thing for SO.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文