我正在编写一个应用程序,需要显示地址,以便我以后可以使用它.我从LocationManager获取位置,并希望在按下时显示显示地址的Toast.我的问题是,当按下按钮时,没有任何反应.(甚至没有在LogCat中)
这是代码:
Button getTaxi = (Button) findViewById(R.id.GetTaxi);
getTaxi.setOnClickListener(new View.OnClickListener() {
public void getAddress() {
Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
String result = null;
try {
List<Address> list = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (list != null && list.size() > 0) {
Address address = list.get(0);
// sending back first address line and locality
result = address.getAddressLine(0) + ", " + address.getLocality();
}
} catch (IOException e) {
String exception = String.format("IOException!!");
Toast.makeText(getApplicationContext(), exception, Toast.LENGTH_LONG);
} finally {
if (result != …Run Code Online (Sandbox Code Playgroud) 我尝试使用Google maps API开发Android地图应用程序.
使用Google API在多个emulatet Android设备(2.1; 2.3.3; 4.0.3)上进行测试.
问题是logcat向我抛出:
02-05 04:39:57.519: E/AndroidRuntime(588): FATAL EXCEPTION: main
02-05 04:39:57.519: E/AndroidRuntime(588): java.lang.RuntimeException: Unable to start activity ComponentInfo{map.test.activity/map.test.activity.MapTestActivity}: java.lang.SecurityException: Provider gps requires ACCESS_FINE_LOCATION permission
02-05 04:39:57.519: E/AndroidRuntime(588): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-05 04:39:57.519: E/AndroidRuntime(588): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-05 04:39:57.519: E/AndroidRuntime(588): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-05 04:39:57.519: E/AndroidRuntime(588): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-05 04:39:57.519: E/AndroidRuntime(588): at android.os.Handler.dispatchMessage(Handler.java:99)
02-05 04:39:57.519: E/AndroidRuntime(588): at android.os.Looper.loop(Looper.java:130)
02-05 04:39:57.519: E/AndroidRuntime(588): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-05 04:39:57.519: E/AndroidRuntime(588): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 04:39:57.519: E/AndroidRuntime(588): at java.lang.reflect.Method.invoke(Method.java:507)
02-05 04:39:57.519: E/AndroidRuntime(588): at …Run Code Online (Sandbox Code Playgroud)