无法解析服务器的响应

时间:2011-07-04 17:28:36

标签: android reverse-geocoding

我完全厌倦了:无法在我的代码中解析服务器的响应:

try {
    List<Address> addresses = g.getFromLocation(lat, lng, 1);
    if(addresses.size()>0) {
        address = addresses.get(0);
        for(int i=0;i<address.getMaxAddressLineIndex();i++) {
            add+=address.getAddressLine(i)+"\n";
            }
        Toast.makeText(this, add, Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(this, "we failed to locate the address",Toast.LENGTH_LONG).show();
    }
} catch (IOException e) {
    e.printStackTrace();
    Toast.makeText(this, "i dnt knw", Toast.LENGTH_LONG);
}

我得到Toast,“我们找不到地址”。也用在手机上。 同样的错误。我使用的权限是:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.LOCATION" />

LAT LONG的代码:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchscreen);
//comment the display and on click listener to run any other xml except main
LocationManager mlocManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
MyLocationListen mlocListener = new MyLocationListen();
location = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, locListener);

if(location!=null) {
    CurLat = location.getLatitude();
    CurLong=location.getLongitude();
} else {
    Toast.makeText(this, "Cant find location", Toast.LENGTH_LONG).show(); }

Toast.makeText(this, "LAT="+CurLat+" LONG="+CurLong, Toast.LENGTH_LONG).show();
Log.d("test","here"+ " LAT="+CurLat+" LONG="+CurLong);
CurLocation = (TextView)findViewById(R.id.LocationText);
CurLocation.setText(getAddress(CurLat,CurLong));

0 个答案:

没有答案
相关问题