android - Can I implement the reverse geocoding function within my ActivityMaps.java file? -
im developing app in android studio 1.1.0 , have implemented google maps api can retrieve users current location convert address. can use following code in mapsactivity.java file?
function getreversegeocodingdata(lat, lng) { var latlng = new google.maps.latlng(lat, lng); // making geocode request var geocoder = new google.maps.geocoder(); geocoder.geocode({ 'latlng': latlng }, function (results, status) { if (status !== google.maps.geocoderstatus.ok) { alert(status); } // checking see if geoeode status ok before proceeding if (status == google.maps.geocoderstatus.ok) { console.log(results); var address = (results[0].formatted_address); } });
}
any appreciated. still relatively new android studio
you can using android.location.geocoder.
// current locality based on lat lng geocoder geocoder; list<address> addresses; geocoder = new geocoder(this, locale.getdefault()); addresses = geocoder.getfromlocation(latitude, longitude, 1); // here 1 represent max location result returned, documents recommended 1 5 string address = addresses.get(0).getaddressline(0); // if additional address line present only, check max available address lines getmaxaddresslineindex() string city = addresses.get(0).getlocality(); string state = addresses.get(0).getadminarea(); string country = addresses.get(0).getcountryname(); string postalcode = addresses.get(0).getpostalcode(); string knownname = addresses.get(0).getfeaturename();
for practice make sure inside asynctask.
Comments
Post a Comment