java.io.IOException:无法解析 getFromLocationName() 处服务器的响应

发布于 2024-12-12 12:27:26 字数 564 浏览 0 评论 0原文

我知道这个问题以前经常被问到,但我无法从任何答案或搜索结果中找到解决方案。 我必须尽快解决这个问题.. 我试图从用户输入的地址中获取纬度和经度,但我继续得到:

java.io.IOException: Unable to parse response from server 

我正在使用此代码:

        Geocoder geocoder = new Geocoder(this ,Locale.getDefault());
        String newAddress = (String)saveas.getText().toString();
        List<Address> addresses = geocoder.getFromLocationName(newAddress, 1);

我尝试了很多不同的可能方法,但没有任何效果... 默认地图应用程序运行良好,当用户输入地址时,它会在地图中成功显示该地址..我该如何做同样的事情..?

我已经添加了所有必需的权限,并且正在真实设备上测试它(版本 2.3)...

I know the question has been asked frequently before ,but i am unable to get the solution from any answer or search results.
I have to solve this issue ASAP ..
I am trying to get the latitude and the longitude from the address enter by the user but i am continue getting :

java.io.IOException: Unable to parse response from server 

I am using this code :

        Geocoder geocoder = new Geocoder(this ,Locale.getDefault());
        String newAddress = (String)saveas.getText().toString();
        List<Address> addresses = geocoder.getFromLocationName(newAddress, 1);

I tried a lot with different possible ways but nothing works...
The default map application works well, when the user enter the address it shows sucessfully that address in the map..How can i do the same..?

I have added all the required permissions and i am testing it on the real device(version 2.3)...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

阪姬 2024-12-19 12:27:26

您尝试过 3G 连接吗?我注意到,如果您从 wifi 发送多个反向地理定位请求,看起来您的 IP 会在一段时间后被阻止,并且反向地理定位将在一段时间内不会响应。当我遇到类似问题时,切换到 3G 使这个请求对我有用。

Have you tried over a 3G connection? I've noticed that if you send several reverse geolocation requests from wifi, it looks like your IP is blocked after a while and the reverse geolocation won't respond for an amount of time. Switching to 3G made the request work for me when I had similar issues.

时间海 2024-12-19 12:27:26

我的三星 Galaxy Tab 10.1 也遇到了同样的问题。我花了好几个小时寻找解决方案,但没有任何帮助。要解决问题,请尝试以下操作:

转至位置设置并启用:

1.使用无线网络
2.使用GPS卫星

等待GPS定位修复

此后,地理编码器服务器开始响应。即使我禁用了无线和 GPS 定位,服务器仍然在工作。我认为只有当您与 Google 共享您的位置时才能使用地理编码器。

I had the same problem with my Samsung Galaxy Tab 10.1. I search hours for a solution and nothing helped. To fix issues try following:

Go to Location settings and enable:

1.Use Wireless networks
2.Use GPS satellites

wait for GPS location fix

After this, geocoder server starts responding. Even when I disabled wireless and GPS Location is server still working. I think geocoder only can be used if you share your location with Google.

深陷 2024-12-19 12:27:26

我通过改变上下文解决了同样的问题。

我使用 Fragment,所以我的代码是这样的

    public class SearchRoteFragment extends Fragment{

        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.teste_mapa, container, false);
        context = getActivity();
...
}

,当我调用地理编码时我这样做

Geocoder geoCoder = new Geocoder(context, Locale.getDefault());

I solved the same issue changing the context.

I use Fragment, so my code is like this

    public class SearchRoteFragment extends Fragment{

        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.teste_mapa, container, false);
        context = getActivity();
...
}

and when I call geocode I do this

Geocoder geoCoder = new Geocoder(context, Locale.getDefault());
未蓝澄海的烟 2024-12-19 12:27:26

如果您在创建地理编码器时设置区域设置参数,这可能会很有用:

yourGeocoder = new Geocoder(this, Locale.CANADA); 

请将第二个参数替换为最佳值。

我猜想默认区域设置值可能与您使用的地图区域不对应。

It may be useful if you set the locale parameter when creating Geocoder:

yourGeocoder = new Geocoder(this, Locale.CANADA); 

Please replace the second parameter with the best value.

I guess that the default locale value may be not corresponding the map region that you use.

沐歌 2024-12-19 12:27:26

我不知道它是否有帮助,顺便说一句,下面是我的项目的片段,工作正常,修改它以满足您的需求

String newAddress = saveas.getText().toString();
searchFromLocationName(newAddress);


private void searchFromLocationName(String name){
 try {
  List<Address> result
  = myGeocoder.getFromLocationName(name, MAX_RESULT);

  if ((result == null)||(result.isEmpty())){
   Toast.makeText(AndroidgetFromLocationNameActivity.this,
     "No matches were found or there is no backend service!",
     Toast.LENGTH_LONG).show();
  }else{

   MyArrayAdapter adapter = new MyArrayAdapter(this,
         android.R.layout.simple_list_item_1, result);
   listviewResult.setAdapter(adapter);

   Toast.makeText(AndroidgetFromLocationNameActivity.this,
     "Finished!",
     Toast.LENGTH_LONG).show();
  }


 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  Toast.makeText(AndroidgetFromLocationNameActivity.this,
    "The network is unavailable or any other I/O problem occurs!",
    Toast.LENGTH_LONG).show();
 }
}

I dont know if it helps BTW below is snippet from my project working fine modify it to suit your needs

String newAddress = saveas.getText().toString();
searchFromLocationName(newAddress);


private void searchFromLocationName(String name){
 try {
  List<Address> result
  = myGeocoder.getFromLocationName(name, MAX_RESULT);

  if ((result == null)||(result.isEmpty())){
   Toast.makeText(AndroidgetFromLocationNameActivity.this,
     "No matches were found or there is no backend service!",
     Toast.LENGTH_LONG).show();
  }else{

   MyArrayAdapter adapter = new MyArrayAdapter(this,
         android.R.layout.simple_list_item_1, result);
   listviewResult.setAdapter(adapter);

   Toast.makeText(AndroidgetFromLocationNameActivity.this,
     "Finished!",
     Toast.LENGTH_LONG).show();
  }


 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  Toast.makeText(AndroidgetFromLocationNameActivity.this,
    "The network is unavailable or any other I/O problem occurs!",
    Toast.LENGTH_LONG).show();
 }
}
空城旧梦 2024-12-19 12:27:26

可能您的手机未连接,无法从服务器检索答案。

正如此处解释的那样

throws IOException if the network is unavailable or any other I/O problem occurs

Probably your phone is not connected and can't retrieve an answer from the server.

As explained here geocoder

throws IOException if the network is unavailable or any other I/O problem occurs
白龙吟 2024-12-19 12:27:26

我正在 Android 2.3.4 上进行测试,并收到“无法解析服务器响应”异常。

确保你的谷歌地图可以工作,我的不能工作!一旦谷歌地图开始工作地理编码器
很好。

我确实切换了“使用无线网络”和“使用无线网络”。 “位置和安全”设置中的“使用 GPS 卫星”。

I was testing on Android 2.3.4, and received "Unable to parse response from server" exception.

Make sure your google map is working, mine was not working! Once google map started working Geocoder
was fine.

I did toggled "Use wireless networks" & "Use GPS satellites" from "Location & security" settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文