我正在尋找解決方案來更改郵政編碼,例如DD3 7BN,但不使用地理位置。我找到了一個使用url http://maps.googleapis.com/maps/api/geocode/json?address=DD37bn的解決方案。 一個人提供了另一種解決方案,但它不適合我。如何使用地圖API從郵編中獲取街道名稱?
但它顯示錯誤GRPS失敗。我的問題最好的解決方案是什麼?
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getAddressByPostalCode("");
}
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);
/*TextView street = (TextView)findViewById(R.id.editText1);
TextView pcode = (TextView)findViewById(R.id.editText2);
TextView blk = (TextView)findViewById(R.id.editText3);
TextView build = (TextView)findViewById(R.id.editText4);
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();
}
}
}
我需要這個只用於一個城市。我知道可以有多個結果或null。但我尋找解決方案如何使用例如我發現這個鏈接街道,因爲後來我可以檢查是否這是我期望與否的記錄。 –
如果使用google,你會在「address_components」數組中尋找包含「types」數組的「route」對象。 –
你可以給任何exaples如何在代碼中使用谷歌或我可以找到更多的信息? –