本文介绍了获取城市名称针对Android的纬度和经度为服务不可用的Andr​​oid 4.0.3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的应用程序在Android 4.0.3版本。现在,我想从城市名称或其他信息的天气预报经度
但是当我运行的应用程序是显示我不能使用的服务。

的logcat

  01-10 13:58:29.279:W / System.err的(1211):java.io.IOException异常:服务不可用
    01-10 13:58:29.289:W / System.err的(1211):在android.location.Geo coder.getFromLocation(GEO coder.java:136)
    01-10 13:58:29.299:W / System.err的(1211):在com.example.vixxa.VisitorActivity $ CityAsyncTask.doInBackground(VisitorActivity.java:601)
    01-10 13:58:29.319:W / System.err的(1211):在com.example.vixxa.VisitorActivity $ CityAsyncTask.doInBackground(VisitorActivity.java:1)
    01-10 13:58:29.329:W / System.err的(1211):在android.os.AsyncTask $ 2.call(AsyncTask.java:264)
    01-10 13:58:29.329:W / System.err的(1211):在java.util.concurrent.FutureTask中$ Sync.innerRun(FutureTask.java:305)
    01-10 13:58:29.339:W / System.err的(1211):在java.util.concurrent.FutureTask.run(FutureTask.java:137)
    01-10 13:58:29.349:W / System.err的(1211):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    01-10 13:58:29.349:W / System.err的(1211):在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:569)
    01-10 13:58:29.359:W / System.err的(1211):在java.lang.Thread.run(Thread.java:856)

codeAsynctak.java

 公共类CityAsyncTask扩展的AsyncTask<字符串,字符串,字符串>
    {        @覆盖
        保护字符串doInBackground(字符串... PARAMS){             地理codeR地理codeR =新的地缘codeR(VisitorActivity.this,Locale.getDefault());
                尝试
                {
                    清单<地址>地址=地理coder.getFromLocation(纬度,经度,1);
                    Log.e(地址, - >中+地址);                }
                赶上(IOException异常E)
                {
                    e.printStackTrace();                }            返回null;
        }    }


解决方案

尝试使用这种code,它的工作对我TAB2。

 公共类CityAsyncTask扩展的AsyncTask<字符串,字符串,字符串>
{    @覆盖
    保护字符串doInBackground(字符串... PARAMS){         地理codeR地理codeR =新的地缘codeR(LatLongActivity.this,Locale.getDefault());
            尝试
            {
                清单<地址>地址=地理coder.getFromLocation(纬度,经度,1);
                Log.e(地址, - >中+地址);
                结果= addresses.get(0)的ToString();
            }
            赶上(IOException异常E)
            {
                e.printStackTrace();
            }
        返回结果;
    }
    @覆盖
    保护无效onPostExecute(字符串结果){
        // TODO自动生成方法存根
        super.onPostExecute(结果);
        AlertDialog.Builder警报=新AlertDialog.Builder(LatLongActivity.this);
        alert.setTitle(地址);
        alert.setMessage(结果);
        alert.setNegativeButton(取消,新DialogInterface.OnClickListener(){
            @覆盖
            公共无效的onClick(DialogInterface对话,诠释它){
                // TODO自动生成方法存根
                dialog.dismiss();
            }
        });
        alert.setCancelable(假);
        alert.show();
    }
}

I am using the Android 4.0.3 version in apps. Now I want to get the city name or other information from LATITUDE and LONGITUDEbut when I run the apps is show me service not available.

Logcat

  01-10 13:58:29.279: W/System.err(1211): java.io.IOException: Service not Available
    01-10 13:58:29.289: W/System.err(1211):     at android.location.Geocoder.getFromLocation(Geocoder.java:136)
    01-10 13:58:29.299: W/System.err(1211):     at com.example.vixxa.VisitorActivity$CityAsyncTask.doInBackground(VisitorActivity.java:601)
    01-10 13:58:29.319: W/System.err(1211):     at com.example.vixxa.VisitorActivity$CityAsyncTask.doInBackground(VisitorActivity.java:1)
    01-10 13:58:29.329: W/System.err(1211):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
    01-10 13:58:29.329: W/System.err(1211):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    01-10 13:58:29.339: W/System.err(1211):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    01-10 13:58:29.349: W/System.err(1211):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    01-10 13:58:29.349: W/System.err(1211):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    01-10 13:58:29.359: W/System.err(1211):     at java.lang.Thread.run(Thread.java:856)

CodeAsynctak.java

public class CityAsyncTask extends AsyncTask<String , String,String>
    {

        @Override
        protected String doInBackground(String... params) {

             Geocoder geocoder = new Geocoder(VisitorActivity.this, Locale.getDefault());
                try
                {
                    List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
                    Log.e("Addresses","-->"+addresses);

                }
                catch (IOException e)
                {
                    e.printStackTrace();

                }

            return null;
        }

    }
解决方案

Try using this code, it worked on my TAB2.

public class CityAsyncTask extends AsyncTask<String , String,String>
{

    @Override
    protected String doInBackground(String... params) {

         Geocoder geocoder = new Geocoder(LatLongActivity.this, Locale.getDefault());
            try
            {
                List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
                Log.e("Addresses","-->"+addresses);
                result = addresses.get(0).toString();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        return result;
    }
    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        AlertDialog.Builder alert = new AlertDialog.Builder(LatLongActivity.this);
        alert.setTitle("ADDRESS");
        alert.setMessage(result);
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.dismiss();
            }
        });
        alert.setCancelable(false);
        alert.show();
    }
}

这篇关于获取城市名称针对Android的纬度和经度为服务不可用的Andr​​oid 4.0.3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 09:56