關(guān)于Android高德地圖的簡(jiǎn)單開(kāi)發(fā)實(shí)例代碼(DEMO)
廢話不多說(shuō)了,直接給大家上干貨了。
以下為初次接觸時(shí) ,練手的DEMO
import android.app.Activity; import android.app.ProgressDialog; import android.content.ContentValues; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.Gravity; import android.view.KeyEvent; import android.view.View; import android.widget.AdapterView; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; import com.amap.api.location.AMapLocation; import com.amap.api.location.AMapLocationClient; import com.amap.api.location.AMapLocationClientOption; import com.amap.api.location.AMapLocationListener; import com.amap.api.maps.AMap; import com.amap.api.maps.CameraUpdateFactory; import com.amap.api.maps.LocationSource; import com.amap.api.maps.MapView; import com.amap.api.maps.UiSettings; import com.amap.api.maps.model.BitmapDescriptorFactory; import com.amap.api.maps.model.LatLng; import com.amap.api.maps.model.Marker; import com.amap.api.maps.model.MarkerOptions; import com.amap.api.maps.model.Poi; import com.amap.api.maps.overlay.PoiOverlay; import com.amap.api.services.core.LatLonPoint; import com.amap.api.services.core.PoiItem; import com.amap.api.services.core.SuggestionCity; import com.amap.api.services.geocoder.GeocodeQuery; import com.amap.api.services.geocoder.GeocodeResult; import com.amap.api.services.geocoder.GeocodeSearch; import com.amap.api.services.geocoder.RegeocodeQuery; import com.amap.api.services.geocoder.RegeocodeResult; import com.amap.api.services.help.Inputtips; import com.amap.api.services.help.InputtipsQuery; import com.amap.api.services.help.Tip; import com.amap.api.services.poisearch.PoiResult; import com.amap.api.services.poisearch.PoiSearch; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class BaseMapActivity extends Activity implements View.OnClickListener,LocationSource,AMapLocationListener,TextWatcher,Inputtips.InputtipsLi stener,AMap.OnMarkerClickListener,PoiSearch.OnPoiSearchListener,AMap.OnPOIClickListener,Ge ocodeSearch.OnGeocodeSearchListener{ private MapView mapView; private AMap aMap; private LinearLayout ly_1; private Button bt_map; private AutoCompleteTextView search_keyword; //輸入要搜索的keyword private ListView listview; //keyword 監(jiān)聽(tīng)數(shù)據(jù)形成的列表 private ProgressDialog progDialog = null;// 進(jìn)度條顯示 private LinearLayout ly_2; //ly_1 所包含的布局之一 private Button bt_back1; private ListView history_listview; private TextView history_item_tv; List<Map<String, Object>> listItem; //輸入keyword,數(shù)據(jù)返回的list數(shù)據(jù)源 //====================以下為操作數(shù)據(jù)庫(kù)================== private ArrayList<HashMap<String, Object>> MapHistoryList; //=============地圖定位控件============== private OnLocationChangedListener mListener; private AMapLocationClient mlocationClient; private AMapLocationClientOption mLocationOption; //=============地圖自身UI定義============ private UiSettings mUiSettings; //=============通用地圖控件============== private LatLonPoint mLatLonPoint;//初始定位經(jīng)緯度 private double ms,me; //經(jīng)緯度double值 private String locationAdressName; //=============地圖POI關(guān)鍵字搜索========== private PoiResult poiResult; // poi返回的結(jié)果 private PoiSearch.Query query;// Poi查詢條件類(lèi) private PoiSearch poiSearch;// POI搜索 private static String keyWord = "";// 要輸入的poi搜索關(guān)鍵字 private int currentPage = 0;// 當(dāng)前頁(yè)面,從0開(kāi)始計(jì)數(shù) private Button bt_search; //搜索POI private MarkerOptions options; //========================以下為地理編碼================= private GeocodeSearch geocoderSearch; private static String addressCityDistric; //得到逆地理編碼的 市區(qū) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.base_map_activity); mapView = (MapView) findViewById(R.id.map); mapView.onCreate(savedInstanceState);// 此方法必須重寫(xiě) init(); initUi(); initHistoryList(); } /** * 初始化AMap對(duì)象 */ private void init() { if (aMap == null) { aMap = mapView.getMap(); setUpMap(); } } /** * 設(shè)置一些amap的屬性 */ private void setUpMap() { aMap.setLocationSource(this);// 設(shè)置定位監(jiān)聽(tīng) aMap.getUiSettings().setMyLocationButtonEnabled(true);// 設(shè)置默認(rèn)定位按鈕是否顯示 aMap.setMyLocationEnabled(true);// 設(shè)置為true表示顯示定位層并可觸發(fā)定位,false表示 隱藏定位層并不可觸發(fā)定位,默認(rèn)是false // 設(shè)置定位的類(lèi)型為定位模式 ,可以由定位、跟隨或地圖根據(jù)面向方向旋轉(zhuǎn)幾種 aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE); aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(me,ms), 14)); //當(dāng)前 地圖鏡頭界面 (讓地圖在剛進(jìn)入時(shí)就是這個(gè)的話,需要先得到LatLng值即可,待后續(xù)修正) mUiSettings= aMap.getUiSettings(); //實(shí)例化地圖UI設(shè)置 mUiSettings.setScaleControlsEnabled(true); //比例尺顯示 mUiSettings.setCompassEnabled(false); //指南針不顯示 mLocationOption.setGpsFirst(true); //優(yōu)先返回GPS定位信息 aMap.setOnPOIClickListener(this); //POI 點(diǎn)擊事件監(jiān)聽(tīng) aMap.setOnMarkerClickListener(this); geocoderSearch = new GeocodeSearch(this); geocoderSearch.setOnGeocodeSearchListener(this); // 注冊(cè)地理編碼監(jiān)聽(tīng) } private void initUi(){ ly_1=(LinearLayout)findViewById(R.id.map_2); //地圖隱藏掉顯示的界面 bt_map=(Button)findViewById(R.id.map_bt); //首頁(yè) 按鈕 bt_map.setOnClickListener(this); //返回鍵 bt_back1=(Button)findViewById(R.id.bt_back_1); bt_back1.setOnClickListener(this); //keyword search_keyword=(AutoCompleteTextView)findViewById(R.id.keyWord); search_keyword.addTextChangedListener(this); //keyword輸入list listview=(ListView)findViewById(R.id.map_list); //第二頁(yè)顯示 ly_2=(LinearLayout)findViewById(R.id.history_record); //POI 搜索 按鈕 bt_search=(Button)findViewById(R.id.bt_search); bt_search.setOnClickListener(this); //歷史記錄 list history_listview=(ListView)findViewById(R.id.lv_history); history_item_tv=(TextView)findViewById(R.id.history_item_addressName); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.map_bt: bt_map.setVisibility(View.GONE); mapView.setVisibility(View.GONE); ly_1.setVisibility(View.VISIBLE); break; case R.id.bt_search: // mlocationClient.stopLocation(); searchButton(); bt_map.setVisibility(View.GONE); mapView.setVisibility(View.VISIBLE); ly_1.setVisibility(View.VISIBLE); listview.setVisibility(View.GONE); ly_2.setVisibility(View.GONE); break; case R.id.bt_back_1: aMap.clear(); bt_map.setVisibility(View.VISIBLE); mapView.setVisibility(View.VISIBLE); ly_1.setVisibility(View.GONE); break; } } /** * 方法必須重寫(xiě) */ @Override protected void onResume() { super.onResume(); mapView.onResume(); } /** * 方法必須重寫(xiě) */ @Override protected void onPause() { super.onPause(); mapView.onPause(); } /** * 方法必須重寫(xiě) */ @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mapView.onSaveInstanceState(outState); } /** * 方法必須重寫(xiě) */ @Override protected void onDestroy() { super.onDestroy(); mapView.onDestroy(); } /** * back設(shè)置 * @param keyCode * @param event * @return */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK ) { aMap.clear(); bt_map.setVisibility(View.VISIBLE); mapView.setVisibility(View.VISIBLE); ly_1.setVisibility(View.GONE); } return false; } //========================================================以下為定位 =============================================== /** * 激活定位 */ @Override public void activate(OnLocationChangedListener listener) { mListener = listener; if (mlocationClient == null) { mlocationClient = new AMapLocationClient(this); mLocationOption = new AMapLocationClientOption(); //設(shè)置定位監(jiān)聽(tīng) mlocationClient.setLocationListener(this); //設(shè)置為高精度定位模式 mLocationOption.setLocationMode (AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); //設(shè)置定位參數(shù) mlocationClient.setLocationOption(mLocationOption); // 此方法為每隔固定時(shí)間會(huì)發(fā)起一次定位請(qǐng)求,為了減少電量消耗或網(wǎng)絡(luò)流量消耗, // 注意設(shè)置合適的定位時(shí)間的間隔(最小間隔支持為2000ms),并且在合適時(shí)間調(diào)用 stopLocation()方法來(lái)取消定位請(qǐng)求 // 在定位結(jié)束后,在合適的生命周期調(diào)用onDestroy()方法 // 在單次定位情況下,定位無(wú)論成功與否,都無(wú)需調(diào)用stopLocation()方法移除請(qǐng)求, 定位sdk內(nèi)部會(huì)移除 mlocationClient.startLocation(); } } /** * 停止定位 */ @Override public void deactivate() { mListener = null; if (mlocationClient != null) { mlocationClient.stopLocation(); mlocationClient.onDestroy(); } mlocationClient = null; } /** * 定位成功后回調(diào)函數(shù) */ @Override public void onLocationChanged(AMapLocation amapLocation) { if (mListener != null && amapLocation != null) { if (amapLocation != null && amapLocation.getErrorCode() == 0) { mListener.onLocationChanged(amapLocation);// 顯示系統(tǒng)小藍(lán)點(diǎn) Message msg = mHandler.obtainMessage(); //定位成功后,開(kāi)始hangler更新經(jīng)緯 度 msg.obj = amapLocation; msg.what = Utils.MSG_LOCATION_FINISH; mHandler.sendMessage(msg); //當(dāng)前定位后的詳細(xì)位置(省、市、區(qū)、街道信息) locationAdressName=amapLocation.getProvider()+amapLocation.getCity ()+amapLocation.getDistrict()+amapLocation.getAddress(); } else { String errText = "定位失敗," + amapLocation.getErrorCode()+ ": " + amapLocation.getErrorInfo(); Toast.makeText(getApplicationContext(),errText,Toast.LENGTH_SHORT).show(); } } } Handler mHandler = new Handler() { public void dispatchMessage(android.os.Message msg) { switch (msg.what) { //開(kāi)始定位 case Utils.MSG_LOCATION_START: //("正在定位..."); break; // 定位完成 case Utils.MSG_LOCATION_FINISH: AMapLocation loc = (AMapLocation) msg.obj; String result = Utils.getLocationStr(loc); // (result); ms=Utils.jingdu; me=Utils.weidu; mLatLonPoint=new LatLonPoint(me,ms); break; //停止定位 case Utils.MSG_LOCATION_STOP: // ("定位停止"); break; default: break; } }; }; //=========================================以下為keyword 改變監(jiān)聽(tīng) =================================== @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence s, int start, int stop, int count) { String newText = s.toString().trim(); //在這里判斷 是否有輸入 if(s.length()<1){ ly_2.setVisibility(View.VISIBLE); listview.setVisibility(View.GONE); }else { ly_2.setVisibility(View.GONE); mapView.setVisibility(View.GONE); listview.setVisibility(View.VISIBLE); } if (!AMapUtil.IsEmptyOrNullString(newText)) { InputtipsQuery inputquery = new InputtipsQuery(newText, Utils.city); Inputtips inputTips = new Inputtips(BaseMapActivity.this, inputquery); inputTips.setInputtipsListener(this); //設(shè)置=======得到數(shù)據(jù)監(jiān)聽(tīng)======= inputTips.requestInputtipsAsyn(); } } @Override public void afterTextChanged(Editable editable) { } //=======得到數(shù)據(jù)監(jiān)聽(tīng)======= @Override public void onGetInputtips(List<Tip> tipList, int rCode) { if (rCode == 1000) {// 正確返回 //監(jiān)聽(tīng)反饋回來(lái)的數(shù)據(jù)當(dāng)做listView數(shù)據(jù)源 listItem=new ArrayList<Map<String,Object>>(); for (int i = 0; i < tipList.size(); i++) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("mapName",tipList.get(i).getName()); map.put("mapAddress",tipList.get(i).getDistrict()); map.put("mapPosition",tipList.get(i).getPoint()); listItem.add(map); } listview.setAdapter(new MapListAdapter(this,listItem)); //輸入時(shí)keyword 產(chǎn)生的列表的 item點(diǎn)擊事件 listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { aMap.clear(); mlocationClient.stopLocation(); LatLonPoint latLonPoint=(LatLonPoint)(listItem.get(i).get ("mapPosition")); Double dd=latLonPoint.getLatitude(); Double ee=latLonPoint.getLongitude(); options=new MarkerOptions(); Marker marker=aMap.addMarker(options.position(new LatLng(dd,ee))); // 做marker標(biāo)記 marker.setVisible(true); aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(dd,ee), 14));//移動(dòng)視圖 bt_map.setVisibility(View.GONE); mapView.setVisibility(View.VISIBLE); ly_1.setVisibility(View.VISIBLE); listview.setVisibility(View.GONE); ly_2.setVisibility(View.GONE); Toast.makeText(getApplicationContext(),""+listItem.get(i).get ("mapPosition"),Toast.LENGTH_SHORT).show(); } }); } else { ToastUtil.showerror(this, rCode); } } //==========================================以下為POI關(guān)鍵字搜索 ===================================================== /** * 顯示進(jìn)度框 */ private void showProgressDialog() { if (progDialog == null) progDialog = new ProgressDialog(this); progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progDialog.setIndeterminate(false); progDialog.setCancelable(false); progDialog.setMessage("正在搜索:\n" + keyWord); progDialog.show(); } /** * 隱藏進(jìn)度框 */ private void dissmissProgressDialog() { if (progDialog != null) { progDialog.dismiss(); } } /** * 點(diǎn)擊搜索按鈕 */ public void searchButton() { keyWord = AMapUtil.checkEditText(search_keyword); if ("".equals(keyWord)) { ToastUtil.show(BaseMapActivity.this, "請(qǐng)輸入搜索關(guān)鍵字"); return; } else { doSearchQuery(); if (MapHistoryList.size()>0){ for (int i=0;i<MapHistoryList.size();i++){ if (keyWord.equals(MapHistoryList.get(i).get("mapHistoryName").toString ())){ return; } }} map_addToHistory(); //增加數(shù)據(jù)到數(shù)據(jù)庫(kù) } } /** * 開(kāi)始進(jìn)行poi搜索 */ protected void doSearchQuery() { showProgressDialog();// 顯示進(jìn)度框 mlocationClient.stopLocation(); //停止定位 20160812 query = new PoiSearch.Query(keyWord, "", Utils.city);// 第一個(gè)參數(shù)表示搜索字符串第二個(gè)參數(shù)表示poi搜索類(lèi)型,第三個(gè)參數(shù)表示poi搜索區(qū)域(空字符串代表全國(guó)) query.setPageSize(20);// 設(shè)置每頁(yè)最多返回多少條poiitem query.setPageNum(currentPage);// 設(shè)置查第一頁(yè) poiSearch = new PoiSearch(this, query); poiSearch.setOnPoiSearchListener(this); poiSearch.searchPOIAsyn(); } /** * poi沒(méi)有搜索到數(shù)據(jù),返回一些推薦城市的信息 */ private void showSuggestCity(List<SuggestionCity> cities) { String infomation = "推薦城市\(zhòng)n"; for (int i = 0; i < cities.size(); i++) { infomation += "城市名稱(chēng):" + cities.get(i).getCityName() + "城市區(qū)號(hào):" + cities.get(i).getCityCode() + "城市編碼:" + cities.get(i).getAdCode() + "\n"; } ToastUtil.show(BaseMapActivity.this, infomation); } /** * POI信息查詢回調(diào)方法 */ @Override public void onPoiSearched(PoiResult result, int rCode) { dissmissProgressDialog();// 隱藏對(duì)話框 if (rCode == 1000) { if (result != null && result.getQuery() != null) {// 搜索poi的結(jié)果 if (result.getQuery().equals(query)) {// 是否是同一條 poiResult = result; // 取得搜索到的poiitems有多少頁(yè) List<PoiItem> poiItems = poiResult.getPois();// 取得第一頁(yè)的poiitem數(shù)據(jù),頁(yè)數(shù)從數(shù)字0開(kāi)始 List<SuggestionCity> suggestionCities = poiResult .getSearchSuggestionCitys();// 當(dāng)搜索不到poiitem數(shù)據(jù)時(shí),會(huì)返回含有搜索關(guān)鍵字的城市信息 if (poiItems != null && poiItems.size() > 0) { aMap.clear();// 清理之前的圖標(biāo) PoiOverlay poiOverlay = new PoiOverlay(aMap, poiItems); poiOverlay.removeFromMap(); poiOverlay.addToMap(); poiOverlay.zoomToSpan(); } else if (suggestionCities != null && suggestionCities.size() > 0) { showSuggestCity(suggestionCities); } else { ToastUtil.show(BaseMapActivity.this, "無(wú)返回結(jié)果"); } } } else { ToastUtil.show(BaseMapActivity.this, "無(wú)返回結(jié)果"); } } else { ToastUtil.showerror(this, rCode); } } @Override public void onPoiItemSearched(PoiItem poiItem, int i) { } //===================以下為POI 點(diǎn)擊事件================ @Override public void onPOIClick(Poi poi) { // aMap.clear(); //暫時(shí)去掉 MarkerOptions markOptiopns = new MarkerOptions(); markOptiopns.position(poi.getCoordinate()); TextView textView = new TextView(getApplicationContext()); textView.setText("到"+poi.getName()+"去"); textView.setGravity(Gravity.CENTER); textView.setTextColor(Color.BLACK); textView.setBackgroundResource(R.drawable.dir1); markOptiopns.icon(BitmapDescriptorFactory.fromView(textView)); markOptiopns.icon(BitmapDescriptorFactory.defaultMarker()); aMap.addMarker(markOptiopns); LatLng newLatLng=poi.getCoordinate(); Double ss=newLatLng.latitude; Double se=newLatLng.longitude; // LatLonPoint newLatLonPoint=new LatLonPoint(ss,se); getAddress(new LatLonPoint(ss,se)); // Toast.makeText(getApplicationContext (),"marker"+addressCityDistric,Toast.LENGTH_SHORT).show(); } //==================以下為 marker 點(diǎn)擊事件反饋=================== @Override public boolean onMarkerClick(Marker marker) { Toast.makeText(getApplicationContext(),"marker點(diǎn)擊"+marker.getPosition ()+"--"+marker.getTitle()+"--"+marker.getSnippet(),Toast.LENGTH_SHORT).show(); marker.getPosition(); return false; } //========================以下為地理編碼以及你地理編碼================================ /** * 響應(yīng)地理編碼 */ public void getLatlon(final String name) { // showDialog(); GeocodeQuery query = new GeocodeQuery(name, Utils.city);// 第一個(gè)參數(shù)表示地址,第 二個(gè)參數(shù)表示查詢城市,中文或者中文全拼,citycode、adcode, geocoderSearch.getFromLocationNameAsyn(query);// 設(shè)置同步地理編碼請(qǐng)求 } /** * 響應(yīng)逆地理編碼 */ public void getAddress(final LatLonPoint latLonPoint) { // showDialog(); RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200, GeocodeSearch.AMAP);// 第一個(gè)參數(shù)表示一個(gè)Latlng,第二參數(shù)表示范圍多少米, 第三個(gè)參數(shù)表示是火系坐標(biāo)系還是GPS原生坐標(biāo)系 geocoderSearch.getFromLocationAsyn(query);// 設(shè)置同步逆地理編碼請(qǐng)求 } /** * 地理編碼查詢回調(diào) */ @Override public void onGeocodeSearched(GeocodeResult result, int rCode) { // dismissDialog(); if (rCode == 1000) { if (result != null && result.getGeocodeAddressList() != null && result.getGeocodeAddressList().size() > 0) { // GeocodeAddress address = result.getGeocodeAddressList().get(0); // aMap.animateCamera(CameraUpdateFactory.newLatLngZoom( // AMapUtil.convertToLatLng(address.getLatLonPoint()), 15)); // geoMarker.setPosition(AMapUtil.convertToLatLng(address // .getLatLonPoint())); // addressName = "經(jīng)緯度值:" + address.getLatLonPoint() + "\n位置描 述:" // + address.getFormatAddress(); } } else { ToastUtil.showerror(this, rCode); } } /** * 逆地理編碼回調(diào) */ @Override public void onRegeocodeSearched(RegeocodeResult result, int rCode) { // dismissDialog(); if (rCode == 1000) { if (result != null && result.getRegeocodeAddress() != null) { addressCityDistric = result.getRegeocodeAddress().getFormatAddress(); TextView tv=(TextView)findViewById(R.id.address_name); tv.setText(addressCityDistric); Log.e("fans",""+addressCityDistric); } else { ToastUtil.showerror(this, rCode); } } } } 資源文件如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.gaodemap.BaseMapActivity"> <Button android:id="@+id/map_bt" android:layout_width="260dp" android:layout_height="40dp" android:text="|查地點(diǎn)、搜路線" android:layout_marginLeft="10dp" android:layout_marginTop="7dp" android:background="@android:color/white" /> <com.amap.api.maps.MapView android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" > </com.amap.api.maps.MapView> <LinearLayout android:id="@+id/ly_address_route" android:layout_width="350dp" android:layout_height="70dp" android:orientation="vertical" android:layout_centerHorizontal="true" android:layout_marginTop="450dp" android:background="@android:color/darker_gray" > <LinearLayout android:layout_width="match_parent" android:layout_height="40dp" android:orientation="horizontal" > <TextView android:id="@+id/address_name" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center"/> <TextView android:id="@+id/xiangqing" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3" android:text="詳情" android:gravity="center" /> </LinearLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="1dp" android:background="@android:color/black"></FrameLayout> <TextView android:id="@+id/route_tv" android:layout_width="match_parent" android:layout_height="29dp" android:text="路徑規(guī)劃" android:gravity="center"/> </LinearLayout> <LinearLayout android:id="@+id/map_2" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:visibility="gone"> <LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:orientation="horizontal"> <Button android:id="@+id/bt_back_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="返回"/> <AutoCompleteTextView android:id="@+id/keyWord" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="請(qǐng)輸入關(guān)鍵字" android:textSize="14dp" android:imeOptions="actionDone" android:inputType="text|textAutoComplete" android:maxLength="20" android:layout_weight="2"/> <Button android:id="@+id/bt_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="搜索"/> </LinearLayout> <ListView android:id="@+id/map_list" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"></ListView> <LinearLayout android:id="@+id/history_record" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@android:color/darker_gray" > <TextView android:id="@+id/history_tv" android:layout_width="match_parent" android:layout_height="50dp" android:text="歷史記錄" android:textSize="16dp" android:gravity="center" /> <ListView android:id="@+id/lv_history" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp"></ListView> <TextView android:id="@+id/zero_history_tv" android:layout_width="match_parent" android:layout_height="50dp" android:text="清空歷史記錄" android:textSize="16dp" android:gravity="center" /> </LinearLayout> </LinearLayout> </RelativeLayout> 代碼中相關(guān)的工具類(lèi),即官方DEMO 中提供的工具類(lèi),并沒(méi)什么改變。。 好了,初步的使用就是這樣。 清單文件中相關(guān)權(quán)限 <!--地圖相關(guān)權(quán)限--> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <!-- 定位需要的服務(wù) 使用2.0的定位需要加上這個(gè) --> <service android:name="com.amap.api.location.APSService" ></service> 申請(qǐng)官方相關(guān)key ,根據(jù)自己androdi studio 上的sha1值和包名來(lái)獲取 <meta-data android:name="com.amap.api.v2.apikey" android:value="xxxxxxxxxxxxxxxxxxxxxxx" />
以上所述是小編給大家介紹的關(guān)于Android高德地圖的簡(jiǎn)單開(kāi)發(fā)實(shí)例代碼(DEMO),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Android應(yīng)用中通過(guò)Layout_weight屬性用ListView實(shí)現(xiàn)表格
這篇文章主要介紹了Android應(yīng)用中通過(guò)Layout_weight屬性用ListView實(shí)現(xiàn)表格的方法,文中對(duì)Layout_weight屬性先有一個(gè)較為詳細(xì)的解釋,需要的朋友可以參考下2016-04-04Android studio實(shí)現(xiàn)左右滑動(dòng)切換圖片
這篇文章主要為大家詳細(xì)介紹了Android studio實(shí)現(xiàn)左右滑動(dòng)切換圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05android TextView多行文本(超過(guò)3行)使用ellipsize屬性無(wú)效問(wèn)題的解決方法
這篇文章介紹了android TextView多行文本(超過(guò)3行)使用ellipsize屬性無(wú)效問(wèn)題的解決方法,有需要的朋友可以參考一下2013-09-09Android提高之SQLite分頁(yè)讀取實(shí)現(xiàn)方法
這篇文章主要介紹了Android的SQLite分頁(yè)讀取實(shí)現(xiàn)方法,在Android項(xiàng)目開(kāi)發(fā)中非常實(shí)用,需要的朋友可以參考下2014-08-08簡(jiǎn)單仿寫(xiě)Android控件SlidingMenu的實(shí)例代碼
下面小編就為大家分享一篇簡(jiǎn)單仿寫(xiě)Android控件SlidingMenu的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01Android編程使用ListView實(shí)現(xiàn)數(shù)據(jù)列表顯示的方法
這篇文章主要介紹了Android編程使用ListView實(shí)現(xiàn)數(shù)據(jù)列表顯示的方法,實(shí)例分析了Android中ListView控件的使用技巧,需要的朋友可以參考下2016-01-01Android自定義View實(shí)現(xiàn)比賽時(shí)間閃動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)比賽時(shí)間閃動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03Android?Studio打包?aar實(shí)現(xiàn)步驟示例詳解
這篇文章主要為大家介紹了Android?Studio打包aar步驟示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08Android側(cè)滑導(dǎo)航欄的實(shí)例代碼
這篇文章主要介紹了Android側(cè)滑導(dǎo)航欄的實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2017-01-01Android Studio導(dǎo)入so文件到項(xiàng)目中的實(shí)例詳解
這篇文章主要介紹了Android Studio導(dǎo)入so文件到項(xiàng)目中的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下2017-09-09