Getting street name from Address/Location object in Android

前端 未结 6 758
滥情空心
滥情空心 2021-01-31 11:34

I\'m trying to get the street name of my current location but I can\'t seem to get it.

I use this method to retrieve the Address:

public Address getAddre         


        
6条回答
  •  情歌与酒
    2021-01-31 11:57

    Try something like this in your code

    String cityName=null;              
    Geocoder gcd = new Geocoder(getBaseContext(),Locale.getDefault());               
    List
    addresses; try { addresses = gcd.getFromLocation(location.getLatitude(), location .getLongitude(), 1); if (addresses.size() > 0) StreetName=addresses.get(0).getThoroughfare(); String s = longitude+"\n"+latitude + "\n\nMy Currrent Street is: "+StreetName; Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();

    it works for me :-) Good luck ;-)

提交回复
热议问题