开发者

android geocoder---nothing is displayed on screen whenn the i run the application

i have written the code for geocoding..but unfortunately it does not work ie nothing is displayed on screen...i am attaching the code...can someone please tell me what is the fault in the code..thanks

public class geocoder extends Activity {

 // private TextView output;
 private LocationManager mgr;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mgr = (LocationManager) getSystemService(LOCATION_SERVICE);

        Geocoder geocoder = new Geocoder(this, Locale.US);
        // output = (TextView) findViewById(R.id.output);
    开发者_运维百科    String staddress = "Georgia Tech, Atlanta, GA";
       //  List<Address> loc = null;
        try{
         List<Address> loc = geocoder.getFromLocationName(staddress, 5);
        }
        catch(IOException e) {
         Log.e("IOException", e.getMessage()); 

        }
        // output = (TextView) findViewById(R.id.output);
    }
}


Nothing is being displayed on the screen because you're not telling anything to display on the screen.

You store the geocoding result in the variable loc, then do nothing with it.

Calling findViewById(R.id.output) is correct; you need to actually update that TextView with what you want to see.

e.g. as a super-basic I-haven't-read-the-Address-Javadoc example:

// Do some geocoding
List<Address> loc = geocoder.getFromLocationName(staddress, 5);

// Find the 'output' TextView defined in main.xml
TextView info = (TextView) findViewById(R.id.output);

// Show the first geocoded result in the 'output' TextView
info.setText("Address: "+ loc.get(0).toString());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜