我正在寻找解决方案来更改邮政编码,例如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如何在代码中使用谷歌或我可以找到更多的信息? –