获取经纬度

Getting latitude and longitude

伙计们请告诉我为什么这个代码显示没有提供者可用

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = lm.getBestProvider(criteria, false);
Location loc = lm.getLastKnownLocation(provider);
if (loc != null) {
    Toast.makeText(this, "Provider" + provider + " has been selected", Toast.LENGTH_LONG).show();
} else {
    tv.setText("No provider Available");
}

可能您忘记在清单中定义权限。

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

阅读文档:http://developer.android.com/training/location/retrieve-current.html#GetLocation