gpt4 book ai didi

android - 在 Android 应用程序中使用邮政编码搜索新加坡地址

转载 作者:行者123 更新时间:2023-11-30 03:09:57 24 4
gpt4 key购买 nike

我想在 android 应用程序 中使用邮政编码 搜索新加坡地址,就像我将邮政编码放在编辑文本字段 436914 然后按 a按钮,它将返回地址“121 Tanjong Rhu Road, Singapore 436914”

我正在使用 android 地理编码类,但它提供的地址与我想要的不完全一样,它给了我 仅限新加坡 436914以及以下链接 http://maps.googleapis.com/maps/api/geocode/json?address=436914&sensor=true

最佳答案

现在我找到了两种使用邮政编码获取地址的方法,http://maps.googleapis.com/maps/api/geocode/json?address=436914&sensor=true链接给出纬度和经度调用相同的 url 但现在而不是地址参数传递 latlong 参数,它的值在两个过程中你将得到准确的地址。

第二种选择是

public void getAddressByPostalCode(String val_pcode) {

Geocoder geocoder = new Geocoder(this.getApplicationContext(), Locale.getDefault());

try {

List<Address> addresses1 = geocoder.getFromLocationName (val_pcode, 1);

Address obj1 = addresses1.get(0);

List<Address> addresses = geocoder.getFromLocation(obj1.getLatitude(), obj1.getLongitude(), 1);
Address obj = addresses.get(0);
EditText street = (EditText)findViewById(R.id.editText3);
EditText pcode = (EditText)findViewById(R.id.editText4);
EditText blk = (EditText)findViewById(R.id.editText13);
EditText build = (EditText)findViewById(R.id.buildingtext);

street.setText(obj.getThoroughfare());
pcode.setText(obj.getPostalCode());
blk.setText(obj.getSubThoroughfare());
build.setText(obj.getPremises());


} catch (IOException e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}

关于android - 在 Android 应用程序中使用邮政编码搜索新加坡地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21138540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com