无法获得当前GPS定位坐标 [英] Unable to get current GPS Location co-ordinates
问题描述
我一直在努力让我的当前位置的GPS坐标,但是我从来没有应用程序锁定到GPS卫星。
I have been trying hard to get my current location's GPS co-ordinates but my app never locks on to a GPS satellite.
在通知区域的图标GPS只是不断闪烁。
The GPS icon in the notification area just keeps on blinking.
虽然我尝试使用谷歌地图在Android(在pre-安装的应用程序),并且事情是能够在LOCKON约60秒!在两者的情况下,我的3G数据连接被上和工作切换。
Whereas I tried using Google Maps on Android (the pre-installed app) and that thing is able to lockon in approx 60 secs! In both of the cases my 3G data connection was switched on and working.
更新:我使用的是Android 2.3.3(的HTC Desire S(出厂安装的操作系统,没有更新应用))的logcat输出的此处。现在,这是没有设置 LocationUpdates()的最小时间和更新之间的最小距离为0,0。
Update: I am using Android 2.3.3 (HTC Desire S (Factory installed OS; no updates applied)) Logcat output is here. Now this is without setting LocationUpdates()
's min time and min-distance between update to 0, 0.
更新#2:我的前面code是这里(引擎收录链接)。
Update #2: My earlier code is here(PasteBin Link).
更新3:的现在,我显示吐司后 onStatusChanged得到一个强制关闭。可用。在()
。
Update #3: Now, I am getting a force close after displaying a Toast .."Available".. in on onStatusChanged()
.
更新#4:的Finally..I得到它的工作。
Update #4: Finally..I got it to work.
-
结果那么,是不是像在谷歌地图的应用会使用一些专有code锁定到GPS信号?我一直在使用各种版本的我的code的尝试。尝试使用标准(S),但从来没有得到他们的GPS合作。对我来说,获得precise(〜50英尺精度),通过GPS定位坐标是必须的。
--
So, is it like that the Google map's app uses some proprietary code for locking on to GPS signals? I have tried using various version of my code. Tried using criteria(s) but never got them to work with GPS. For me getting precise (~50ft accuracy) location co-ordinates through GPS is a must.
我的code:
public class LocationDemoActivity extends Activity implements LocationListener {
LocationManager locationManager;
StringBuilder builder;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000l, 50.0f, this);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
locationManager.removeUpdates(this);
locationManager = null;
Intent i = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(i);
}
@Override
public void onLocationChanged(Location location) {
// builder = new StringBuilder();
double lati=location.getLatitude();
double longi=location.getLongitude();
double alti=location.getAltitude();
float acc=location.getAccuracy();
float speed=location.getSpeed();
long time=location.getTime();
System.out.println(lati);
System.out.println(longi);
System.out.println(alti);
System.out.println(acc);
System.out.println(speed);
System.out.println(time);
/*Toast.makeText(this, "Lati: " + lati,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Long: " + longi,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Alti: " + alti,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Acc.: " + acc,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Speed: " + speed,Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Time: " + time,Toast.LENGTH_SHORT).show();*/
builder.append("Longitide: " + location.getLongitude());
builder.append('\n');
builder.append("Latitude: " + location.getLatitude());
builder.append('\n');
builder.append("Altitude: " + location.getAltitude());
builder.append('\n');
builder.append("Accuracy: " + location.getAccuracy());
builder.append('\n');
builder.append("TimeStamp:" + location.getTime());
builder.append('\n');
System.out.println(builder.toString());
Toast.makeText(this, builder.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onProviderDisabled(String provider) {
System.out.println("Provider Disabled:");
Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
@Override
public void onProviderEnabled(String provider) {
System.out.println("Provider Enabled:");
Toast.makeText(this, "GPS is now enabled...", Toast.LENGTH_LONG).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
System.out.println("Status Changed: Out of Service");
Toast.makeText(this, "Status Changed: Out of Service",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
System.out.println("Status Changed: Temporarily Unavailable");
Toast.makeText(this, "Status Changed: Temporarily Unavailable",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.AVAILABLE:
System.out.println("Status Changed: Available");
Toast.makeText(this, "Status Changed: Available",
Toast.LENGTH_SHORT).show();
break;
}
}
}
请做答案,因为这是我和任何帮助非常迫切大大AP preciable:)
Please do answer as it's quite urgent on me and any help is greatly appreciable :)
谢谢..
推荐答案
我问一个相关的问题<一href=\"http://stackoverflow.com/questions/14641019/experience-of-location-services-on-android-using-gps-and-network-providers\">here.
要我看起来像你的GPS在手机上是不是能看到SAT的。你需要让你的办公室/家庭我们到露天。就我而言,我搬到了 NetworkProvider
因为GPS是太笨拙。
To me looks like your GPS on the phone is not able to see the sat's. You need to get our of your office/home onto open air. In my case, I moved to NetworkProvider
since GPS was just too clumsy.
另外请注意,你给的距离和时间的参数都没有文字,其最好的猜测
的API使。所以不要从API回调的响应时间/距离计数。
Also note, that the parameters you give for distance and time are not literal, its the best guess
that the api makes. So dont count on response times/distances from the API callback.
这篇关于无法获得当前GPS定位坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!