java.io.IOException:无法解析 getFromLocationName() 处服务器的响应
我知道这个问题以前经常被问到,但我无法从任何答案或搜索结果中找到解决方案。 我必须尽快解决这个问题.. 我试图从用户输入的地址中获取纬度和经度,但我继续得到:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您尝试过 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.
我的三星 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.
我通过改变上下文解决了同样的问题。
我使用 Fragment,所以我的代码是这样的
,当我调用地理编码时我这样做
I solved the same issue changing the context.
I use Fragment, so my code is like this
and when I call geocode I do this
如果您在创建地理编码器时设置区域设置参数,这可能会很有用:
请将第二个参数替换为最佳值。
我猜想默认区域设置值可能与您使用的地图区域不对应。
It may be useful if you set the locale parameter when creating Geocoder:
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.
我不知道它是否有帮助,顺便说一句,下面是我的项目的片段,工作正常,修改它以满足您的需求
I dont know if it helps BTW below is snippet from my project working fine modify it to suit your needs
可能您的手机未连接,无法从服务器检索答案。
正如此处解释的那样
Probably your phone is not connected and can't retrieve an answer from the server.
As explained here geocoder
我正在 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.