小编Teo*_*nee的帖子

将当前地址显示为Toast

我正在编写一个应用程序,需要显示地址,以便我以后可以使用它.我从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)

java android location button toast

2
推荐指数
1
解决办法
239
查看次数

java.lang.SecurityException:Provider gps需要ACCESS_FINE_LOCATION权限

我尝试使用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)

java android google-maps

0
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×2

java ×2

button ×1

google-maps ×1

location ×1

toast ×1