为什么 getBaseStationLatitude() 不断返回 Integer.MAX_VALUE(未知)?
班级项目&论文工作 - 尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 TelephonyManager 获取位置之前,尝试调用“CellLocation.requestLocationUpdate()”方法。这将强制平台更新小区位置,并且如果设备已注册到 CDMA 网络,则应为您提供有效值:
此方法的文档:
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:
Documentation for this method:
http://developer.android.com/reference/android/telephony/CellLocation.html#requestLocationUpdate()
原因如下:
说:
纬度 = 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:
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
您没有收到有效坐标的真正原因是因为某些手机提供商不提供该信息,或者他们提供了错误的信息。
我为我发布的一款应用程序对此进行了大量的个人研究。并且,尝试帮助您指明正确的方向:(以下是许多不同测试的概括,因此您可能能够找到一种不同的设备)
- 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.)