android-Geocoder.getFromLocationName()在ICS设备中不工作
我有两个装置。一个是HTC WildFire S,另一个是HTC 1V。我在应用程序中使用了android-Geocoder.getFromLocationName()在ICS设备中不工作,android,geocoding,android-maps,Android,Geocoding,Android Maps,我有两个装置。一个是HTC WildFire S,另一个是HTC 1V。我在应用程序中使用了Geocoder.getFromLocationName()。它正在HTC wildfire S中成功运行。但是在HTC1V中,我得到了以下错误。为什么会来?我怎样才能解决这个问题?谁能帮帮我吗 代码 位置选项卡 GeoPoint point = new GeoPoint( (int) (LATITUDE * 1E6),
Geocoder.getFromLocationName()
。它正在HTC wildfire S中成功运行。但是在HTC1V中,我得到了以下错误。为什么会来?我怎样才能解决这个问题?谁能帮帮我吗
代码
位置选项卡
GeoPoint point = new GeoPoint(
(int) (LATITUDE * 1E6),
(int) (LONGITUDE * 1E6));
String n;
public void someRandomMethod() {
n = convertPointToLocation(point);
}
public String convertPointToLocation(GeoPoint point) {
String address = "";
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
point.getLatitudeE6() / 1E6,
point.getLongitudeE6() / 1E6, 1);
if (addresses.size() > 0) {
for (int index = 0; index < addresses.get(0).getMaxAddressLineIndex(); index++)
address += addresses.get(0).getAddressLine(index) + " ";
}
}
catch (IOException e) {
e.printStackTrace();
}
return address;
}
地质点=新的地质点(
(国际)(纬度*1E6),
(int)(经度*1E6));
字符串n;
公共方法(){
n=转换点位置(点);
}
公共字符串转换点定位(地质点){
字符串地址=”;
地理编码器地理编码器=新地理编码器(
getBaseContext(),Locale.getDefault();
试一试{
列表地址=geoCoder.getFromLocation(
point.getLatitudeE6()/1E6,
point.getLongitudeE6()/1E6,1);
如果(地址.size()>0){
for(int index=0;index
我终于找到了答案:
重新启动设备以使Geocoder正常工作。希望它能帮助别人
注意:有人说,如果你使用谷歌API 16,它会起作用。这只是一个警告,说明地理编码器不可用。你在One V上安装了Internet访问设置吗?地理编码器需要访问互联网才能检索结果。编辑:你的应用程序在这个阶段没有崩溃,是吗?是的,我有互联网权限。是的,但是设备有连接吗?测试时您是否可以在设备上浏览web?是否单击了“设置”中的位置服务?在SGS II IC上,它们位于以下位置:设置>位置服务。必须单击其中的选项。我添加了位置服务选项卡。请参考。请不要只为您的答案提供代码。为什么这是答案?这个错误出现在谷歌地图API V1中。。我已经在谷歌地图v2上试过了。。当然,只要对语法做一些修改,它就可以在所有android设备上正常工作。注意:对于Google MAp V2,您不再需要在我的应用程序中导入Google APIs,但V2 MAp不起作用。。。你指的是什么样的进口?最终还是不起作用。。。即使使用API 16。我怎样才能解决这个问题?
06-18 16:28:17.933: W/System.err(4960): java.io.IOException: Service not Available
06-18 16:28:17.953: W/System.err(4960):at android.location.Geocoder.getFromLocationName(Geocoder.java:178)
GeoPoint point = new GeoPoint(
(int) (LATITUDE * 1E6),
(int) (LONGITUDE * 1E6));
String n;
public void someRandomMethod() {
n = convertPointToLocation(point);
}
public String convertPointToLocation(GeoPoint point) {
String address = "";
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
point.getLatitudeE6() / 1E6,
point.getLongitudeE6() / 1E6, 1);
if (addresses.size() > 0) {
for (int index = 0; index < addresses.get(0).getMaxAddressLineIndex(); index++)
address += addresses.get(0).getAddressLine(index) + " ";
}
}
catch (IOException e) {
e.printStackTrace();
}
return address;
}