类(class)项目和论文工作 - 尝试从 CDMA Cell 中提取信息,特别是通过使用 getBaseStationLatitude() 和 getBaseStationLongitude()。返回的值为 MAX_VALUE (2147483647) - 我没有收到实际的纬度/经度。 getBaseStationID()、getNetworkID() 和 getSystemID() 正在返回有效 ID。我已经在 2 个单独的单元格中测试过这个,但没有成功。我的代码贴在下面。 ACCESS_FINE_LOCATION 和 ACCESS_COURSE_LOCATION 都添加到 list 中。在 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);
}
}
最佳答案
在从 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 ()
关于android - 为什么 getBaseStationLatitude() 不断返回 Integer.MAX_VALUE(未知)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5409696/