[英]How do I get the full address of location using Google Places Autocomplete?
I am using Google Places Autocomplete
.我正在使用
Google Places Autocomplete
。 They start typing and when a user clicks on an address in the autocomplete list, I want this address to show in my EditText
.他们开始输入,当用户单击自动完成列表中的地址时,我希望该地址显示在我的
EditText
。
For example, when I click on 22 Moyclare Road, Dublin 13, Ireland
in the image below, I want 22 Moyclare Road, Dublin 13, Ireland
to show in my Edittext
.例如,当我
22 Moyclare Road, Dublin 13, Ireland
单击22 Moyclare Road, Dublin 13, Ireland
时,我希望22 Moyclare Road, Dublin 13, Ireland
显示在我的Edittext
。
But all I am getting is Moyclare Road
, like this:但我得到的只是
Moyclare Road
,就像这样:
I am using the getName
property of place
like: mEditInit.setText(place.getName());
我正在使用
place
的getName
属性,例如: mEditInit.setText(place.getName());
but no matter what property I use I can't get it to display full address.但无论我使用什么属性,我都无法让它显示完整地址。 Any ideas?
有任何想法吗?
Here is the entire code of my onActivityResult
function:这是我的
onActivityResult
函数的完整代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Place place = Autocomplete.getPlaceFromIntent(data);
mEditInit.setText(place.getName());
} else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
// TODO: Handle the error.
Status status = Autocomplete.getStatusFromIntent(data);
// Log.i(TAG, status.getStatusMessage());
} else if (resultCode == RESULT_CANCELED) {
// The user canceled the operation.
}
// super.onActivityResult(requestCode, resultCode, data);
}
}
You need to use the place.getAddress()
method instead of place.getName()
to get the full address of a place.您需要使用
place.getAddress()
方法而不是place.getName()
来获取地点的完整地址。
mEditInit.setText(place.getAddress());
Make sure that you specify the address field, ie Place.Field.ADDRESS
.确保您指定地址字段,即
Place.Field.ADDRESS
。 Refer to Google's documentation .请参阅 Google 的文档。
To get the full address for the Irish place you're searching for, instead of selecting 22 Moyclare Road, Dublin 13, Ireland
, select the Northside result from Autocomplete, ie 22 Moyclare Road, Northside, Dublin 13, Ireland
.要获取您正在搜索的爱尔兰地点的完整地址,请不要选择
22 Moyclare Road, Dublin 13, Ireland
,而是从 Autocomplete 中选择 Northside 结果,即22 Moyclare Road, Northside, Dublin 13, Ireland
。
You'll get the following as output from getAddress
:您将获得以下内容作为
getAddress
输出:
22 Moyclare Rd, Northside, Dublin 13, D13 W2X2, Ireland
As for how to show this in the search bar, check out the accepted answer for related question placeautocompletefragment full address至于如何在搜索栏中显示这一点,请查看相关问题placeautocompletefragment full address的已接受答案
Hope this helps!希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.