【发布时间】:2014-03-16 07:41:21
【问题描述】:
在我的应用程序中,我没有得到当前的纬度和经度
public class MainActivity extends Activity implements
LocationListener {
protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
TextView txtLat;
String lat;
String provider;
protected String latitude, longitude;
protected boolean gps_enabled, network_enabled;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.google_map_send_my_current_latlong);
txtLat = (TextView) findViewById(R.id.textView1);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, this);
}
@Override
public void onLocationChanged(Location location) {
txtLat = (TextView) findViewById(R.id.textView1);
txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:"
+ location.getLongitude());
}
@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude", "disable");
}
@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude", "enable");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude", "status");
}
}
我添加了我的清单
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我想在 TextView 中显示我当前的经纬度。我在真实设备上检查过
【问题讨论】:
-
获取 GPS 锁定需要时间。它可以是几秒钟到几分钟(或者如果你在室内,则永远不会)。如果 GPS 关闭,它也将无法工作。您是否在开启 GPS 的情况下在户外(谷歌地图工作的地方)尝试过?
-
我的 GPS 已开启,我检查了大约两分钟。
-
通知栏中的 GPS 符号 - 是闪烁还是常亮?如果它正在闪烁,则说明您没有锁。 (如果它根本不存在,那就是另一个问题了)。
-
一直在闪烁
-
这意味着您没有 GPS 锁。试着走出去,远离高楼。你的代码在我看来是正确的,但来自 GPS 的卫星信号是我们无法控制的
标签: android google-maps location