アプリを実行しているときに、htc Desire cを使用してジオコードを逆ジオコーディングしようとしていますが、そのスローサービスは利用できません。しかし、GeoCoder.isPresent()は「true」を返しています。問題を見つけるのを手伝ってください。
これは私のコードです:
public class MainActivity extends Activity {
LocationManager lManager;
String provider;
Location location ;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = lManager.getBestProvider(criteria, false);
if(provider!=null && !provider.equals("")){
// Get the location from the given provider
location = lManager.getLastKnownLocation(provider);
}
boolean geoCoder = false;
Geocoder geo = new Geocoder(this, Locale.getDefault());
geoCoder = Geocoder.isPresent();
System.out.println("GEO CODER : "+geoCoder);
try {
List<Address> address = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 3);
System.out.println("Size------------- "+address.size());
/*Address addr = address.get(0);
System.out.println("City "+addr.getLocality());*/
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("in here--------------");
e.printStackTrace();
}
}
ログ:
03-16 10:33:58.609: I/System.out(30398): GEO CODER : true
03-16 10:33:58.609: I/System.out(30398): in here--------------
03-16 10:33:58.609: W/System.err(30398): java.io.IOException: Service not Available
03-16 10:33:58.619: W/System.err(30398): at android.location.Geocoder.getFromLocation(Geocoder.java:136)
03-16 10:33:58.619: W/System.err(30398): at com.example.geocoder.MainActivity.onCreate(MainActivity.java:46)
03-16 10:33:58.619: W/System.err(30398): at android.app.Activity.performCreate(Activity.java:4538)
03-16 10:33:58.629: W/System.err(30398): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
03-16 10:33:58.629: W/System.err(30398): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
03-16 10:33:58.629: W/System.err(30398): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
03-16 10:33:58.629: W/System.err(30398): at android.app.ActivityThread.access$600(ActivityThread.java:139)
03-16 10:33:58.629: W/System.err(30398): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
03-16 10:33:58.629: W/System.err(30398): at android.os.Handler.dispatchMessage(Handler.java:99)
03-16 10:33:58.629: W/System.err(30398): at android.os.Looper.loop(Looper.java:156)
03-16 10:33:58.629: W/System.err(30398): at android.app.ActivityThread.main(ActivityThread.java:4987)
03-16 10:33:58.639: W/System.err(30398): at java.lang.reflect.Method.invokeNative(Native Method)
03-16 10:33:58.639: W/System.err(30398): at java.lang.reflect.Method.invoke(Method.java:511)
03-16 10:33:58.639: W/System.err(30398): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-16 10:33:58.639: W/System.err(30398): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-16 10:33:58.649: W/System.err(30398): at dalvik.system.NativeStart.main(Native Method)