开发者

Why getBaseStationLatitude() keeps returning the Integer.MAX_VALUE (unknown)?

开发者 https://www.devze.com 2023-02-19 12:04 出处:网络
Class project & thesis work - trying to pull information from CDMA Cell, specifically by using the getBaseStationLatitude() & getBaseStationLongitude().The value being returned is the MAX_VALU

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);

   }
}


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()


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


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号