使用Android应用中的邮政编码搜索新加坡地址

问题描述 投票:1回答:3

我想在Android应用程序中使用邮政编码搜索新加坡地址,如果我将邮政编码放入edittext字段436914然后按一个按钮,它将返回地址“121 Tanjong Rhu Road,Singapore 436914”

我正在使用android地理编码类,但它给出的地址不完全符合我的要求,它只给我新加坡436914以及以下链接以及http://maps.googleapis.com/maps/api/geocode/json?address=436914&sensor=true

android google-maps
3个回答
1
投票

现在我找到了两个使用邮政编码获取地址的替代方法,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();
    }

}


0
投票

对于Postal Code,我发现onemap.sg中的数据非常准确。但是对于某些邮政编码,会有不止一个结果。这是因为在同一建筑物内可能存在多个相同邮政编码的列表。尽管如此,它仍然是准确的。

为简单起见,我建议在使用api时查看这个github repo

要查看的关键字段是Address,Building,SearchVal。


0
投票

这是另一种方法。 Geocode.xyz/SG

{
"standard": {
"addresst": "121 TANJONG RHU ROAD",
"stnumber": "121",
"prov": "SG",
"city": "Singapore",
"countryname": "Singapore",
"postal": "436914",
"confidence": "0.5"
},
"longt": "103.87430",
"alt": {
"loc": {
  "longt": "103.87430",
  "city": "Singapore",
  "cc": "2",
  "latt": "1.29662"
}
},
"latt": "1.29662"
}
© www.soinside.com 2019 - 2024. All rights reserved.