MapUtility.apiKey = getResources().getString(R.string.your_api_key);Note: Create the 'your_api_key' string resource and add your api key there
ii) Start Location picker request by putting below code in your view
Intent i =newIntent(MainActivity.this, LocationPickerActivity.class); startActivityForResult(i, ADDRESS_PICKER_REQUEST);Handle your onActivityResult for getting address, latitude and longitude as:
@Overrideprotectedvoid onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode ==ADDRESS_PICKER_REQUEST) {
try {
if (data !=null&& data.getStringExtra(MapUtility.ADDRESS) !=null) {
// String address = data.getStringExtra(MapUtility.ADDRESS);double currentLatitude = data.getDoubleExtra(MapUtility.LATITUDE, 0.0);
double currentLongitude = data.getDoubleExtra(MapUtility.LONGITUDE, 0.0);
Bundle completeAddress =data.getBundleExtra("fullAddress");
/* data in completeAddress bundle "fulladdress" "city" "state" "postalcode" "country" "addressline1" "addressline2"*/
txtAddress.setText(newStringBuilder().append("addressline2: ").append
(completeAddress.getString("addressline2")).append("\ncity: ").append
(completeAddress.getString("city")).append("\npostalcode: ").append
(completeAddress.getString("postalcode")).append("\nstate: ").append
(completeAddress.getString("state")).toString());
txtLatLong.setText(newStringBuilder().append("Lat:").append(currentLatitude).append
(" Long:").append(currentLongitude).toString());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}