问题描述
- 整合高德地图时报错bundle为空
-
.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); } } }); }
解决方案
//在onCreat方法中给aMap对象赋值
setContentView(R.layout.basicmap_activity);
解决方案二:
你最好把代码贴一下,直接看错误提示估计是高歌地图没有初始化
解决方案三:
savedInstanceState为空,mapView.onCreate()调用它报错,建议看一下demo是不是要加判断条件或者给它初始化之类的。
时间: 2024-09-16 01:54:39