.xml
<com.amap.api.maps2d.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="1"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
java
public class AdressActivity extends Activity implements GeocodeSearch.OnGeocodeSearchListener {
private static final String TAG="AdressActivity";
final int FLIP_SPACE=100;
private MapView mapView;
private AMap aMap;
private EditText editText;
private Button button;
private int radiu=80;//地图圆形区域半径
private LatLonPoint point;//地址的经纬度对象
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapView= (MapView) findViewById(R.id.map);
editText= (EditText) findViewById(R.id.new_address_edit_text);
button= (Button) findViewById(R.id.location);
//必须回掉mapview的oncreat方法
mapView.onCreate(savedInstanceState);
mapView.onResume();
init();
//设置使用普通地图
aMap.setMapType(AMap.MAP_TYPE_NORMAL);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(editText.equals("")){
Toast.makeText(AdressActivity.this,getResources().getString(R.string.location_edit_empty),Toast.LENGTH_LONG).show();
}else{
GeocodeSearch geocodeSearch=new GeocodeSearch(AdressActivity.this);
geocodeSearch.setOnGeocodeSearchListener(AdressActivity.this);
GeocodeQuery query=new GeocodeQuery(editText.getText().toString(),"010");
//将中文转换为地址编码
geocodeSearch.getFromLocationNameAsyn(query);
}
}
});
}