获得经纬度

时间:2015-08-06 12:33:40

标签: android location latitude-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");
}

1 个答案:

答案 0 :(得分:0)

Maybe you forgot to define the permissions in the manifest.

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

Read the documentation: http://developer.android.com/training/location/retrieve-current.html#GetLocation