關(guān)于Android高德地圖的簡單開發(fā)實例代碼(DEMO)
廢話不多說了,直接給大家上干貨了。
以下為初次接觸時 ,練手的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)聽數(shù)據(jù)形成的列表
private ProgressDialog progDialog = null;// 進度條顯示
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ù)庫==================
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查詢條件類
private PoiSearch poiSearch;// POI搜索
private static String keyWord = "";// 要輸入的poi搜索關(guān)鍵字
private int currentPage = 0;// 當前頁面,從0開始計數(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);// 此方法必須重寫
init();
initUi();
initHistoryList();
}
/**
* 初始化AMap對象
*/
private void init() {
if (aMap == null) {
aMap = mapView.getMap();
setUpMap();
}
}
/**
* 設置一些amap的屬性
*/
private void setUpMap() {
aMap.setLocationSource(this);// 設置定位監(jiān)聽
aMap.getUiSettings().setMyLocationButtonEnabled(true);// 設置默認定位按鈕是否顯示
aMap.setMyLocationEnabled(true);// 設置為true表示顯示定位層并可觸發(fā)定位,false表示
隱藏定位層并不可觸發(fā)定位,默認是false
// 設置定位的類型為定位模式 ,可以由定位、跟隨或地圖根據(jù)面向方向旋轉(zhuǎn)幾種
aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(me,ms), 14)); //當前
地圖鏡頭界面 (讓地圖在剛進入時就是這個的話,需要先得到LatLng值即可,待后續(xù)修正)
mUiSettings= aMap.getUiSettings(); //實例化地圖UI設置
mUiSettings.setScaleControlsEnabled(true); //比例尺顯示
mUiSettings.setCompassEnabled(false); //指南針不顯示
mLocationOption.setGpsFirst(true); //優(yōu)先返回GPS定位信息
aMap.setOnPOIClickListener(this); //POI 點擊事件監(jiān)聽
aMap.setOnMarkerClickListener(this);
geocoderSearch = new GeocodeSearch(this);
geocoderSearch.setOnGeocodeSearchListener(this); // 注冊地理編碼監(jiān)聽
}
private void initUi(){
ly_1=(LinearLayout)findViewById(R.id.map_2); //地圖隱藏掉顯示的界面
bt_map=(Button)findViewById(R.id.map_bt); //首頁 按鈕
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);
//第二頁顯示
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;
}
}
/**
* 方法必須重寫
*/
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
/**
* 方法必須重寫
*/
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
/**
* 方法必須重寫
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
/**
* 方法必須重寫
*/
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
/**
* back設置
* @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();
//設置定位監(jiān)聽
mlocationClient.setLocationListener(this);
//設置為高精度定位模式
mLocationOption.setLocationMode
(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//設置定位參數(shù)
mlocationClient.setLocationOption(mLocationOption);
// 此方法為每隔固定時間會發(fā)起一次定位請求,為了減少電量消耗或網(wǎng)絡流量消耗,
// 注意設置合適的定位時間的間隔(最小間隔支持為2000ms),并且在合適時間調(diào)用
stopLocation()方法來取消定位請求
// 在定位結(jié)束后,在合適的生命周期調(diào)用onDestroy()方法
// 在單次定位情況下,定位無論成功與否,都無需調(diào)用stopLocation()方法移除請求,
定位sdk內(nèi)部會移除
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)小藍點
Message msg = mHandler.obtainMessage(); //定位成功后,開始hangler更新經(jīng)緯
度
msg.obj = amapLocation;
msg.what = Utils.MSG_LOCATION_FINISH;
mHandler.sendMessage(msg);
//當前定位后的詳細位置(省、市、區(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) {
//開始定位
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)聽
===================================
@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ù)據(jù)監(jiān)聽=======
inputTips.requestInputtipsAsyn();
}
}
@Override
public void afterTextChanged(Editable editable) {
}
//=======得到數(shù)據(jù)監(jiān)聽=======
@Override
public void onGetInputtips(List<Tip> tipList, int rCode) {
if (rCode == 1000) {// 正確返回
//監(jiān)聽反饋回來的數(shù)據(jù)當做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));
//輸入時keyword 產(chǎn)生的列表的 item點擊事件
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標記
marker.setVisible(true);
aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(dd,ee),
14));//移動視圖
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)鍵字搜索
=====================================================
/**
* 顯示進度框
*/
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();
}
/**
* 隱藏進度框
*/
private void dissmissProgressDialog() {
if (progDialog != null) {
progDialog.dismiss();
}
}
/**
* 點擊搜索按鈕
*/
public void searchButton() {
keyWord = AMapUtil.checkEditText(search_keyword);
if ("".equals(keyWord)) {
ToastUtil.show(BaseMapActivity.this, "請輸入搜索關(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ù)庫
}
}
/**
* 開始進行poi搜索
*/
protected void doSearchQuery() {
showProgressDialog();// 顯示進度框
mlocationClient.stopLocation(); //停止定位 20160812
query = new PoiSearch.Query(keyWord, "", Utils.city);// 第一個參數(shù)表示搜索字符串第二個參數(shù)表示poi搜索類型,第三個參數(shù)表示poi搜索區(qū)域(空字符串代表全國)
query.setPageSize(20);// 設置每頁最多返回多少條poiitem
query.setPageNum(currentPage);// 設置查第一頁
poiSearch = new PoiSearch(this, query);
poiSearch.setOnPoiSearchListener(this);
poiSearch.searchPOIAsyn();
}
/**
* poi沒有搜索到數(shù)據(jù),返回一些推薦城市的信息
*/
private void showSuggestCity(List<SuggestionCity> cities) {
String infomation = "推薦城市\(zhòng)n";
for (int i = 0; i < cities.size(); i++) {
infomation += "城市名稱:" + cities.get(i).getCityName() + "城市區(qū)號:"
+ 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();// 隱藏對話框
if (rCode == 1000) {
if (result != null && result.getQuery() != null) {// 搜索poi的結(jié)果
if (result.getQuery().equals(query)) {// 是否是同一條
poiResult = result;
// 取得搜索到的poiitems有多少頁
List<PoiItem> poiItems = poiResult.getPois();// 取得第一頁的poiitem數(shù)據(jù),頁數(shù)從數(shù)字0開始
List<SuggestionCity> suggestionCities = poiResult
.getSearchSuggestionCitys();// 當搜索不到poiitem數(shù)據(jù)時,會返回含有搜索關(guān)鍵字的城市信息
if (poiItems != null && poiItems.size() > 0) {
aMap.clear();// 清理之前的圖標
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,
"無返回結(jié)果");
}
}
} else {
ToastUtil.show(BaseMapActivity.this,
"無返回結(jié)果");
}
} else {
ToastUtil.showerror(this, rCode);
}
}
@Override
public void onPoiItemSearched(PoiItem poiItem, int i) {
}
//===================以下為POI 點擊事件================
@Override
public void onPOIClick(Poi poi) {
// aMap.clear(); //暫時去掉
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 點擊事件反饋===================
@Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(getApplicationContext(),"marker點擊"+marker.getPosition
()+"--"+marker.getTitle()+"--"+marker.getSnippet(),Toast.LENGTH_SHORT).show();
marker.getPosition();
return false;
}
//========================以下為地理編碼以及你地理編碼================================
/**
* 響應地理編碼
*/
public void getLatlon(final String name) {
// showDialog();
GeocodeQuery query = new GeocodeQuery(name, Utils.city);// 第一個參數(shù)表示地址,第
二個參數(shù)表示查詢城市,中文或者中文全拼,citycode、adcode,
geocoderSearch.getFromLocationNameAsyn(query);// 設置同步地理編碼請求
}
/**
* 響應逆地理編碼
*/
public void getAddress(final LatLonPoint latLonPoint) {
// showDialog();
RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200,
GeocodeSearch.AMAP);// 第一個參數(shù)表示一個Latlng,第二參數(shù)表示范圍多少米,
第三個參數(shù)表示是火系坐標系還是GPS原生坐標系
geocoderSearch.getFromLocationAsyn(query);// 設置同步逆地理編碼請求
}
/**
* 地理編碼查詢回調(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="|查地點、搜路線"
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="請輸入關(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)的工具類,即官方DEMO 中提供的工具類,并沒什么改變。。
好了,初步的使用就是這樣。
清單文件中相關(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" />
<!-- 定位需要的服務 使用2.0的定位需要加上這個 -->
<service android:name="com.amap.api.location.APSService" ></service>
申請官方相關(guān)key ,根據(jù)自己androdi studio 上的sha1值和包名來獲取
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="xxxxxxxxxxxxxxxxxxxxxxx" />
以上所述是小編給大家介紹的關(guān)于Android高德地圖的簡單開發(fā)實例代碼(DEMO),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Android應用中通過Layout_weight屬性用ListView實現(xiàn)表格
這篇文章主要介紹了Android應用中通過Layout_weight屬性用ListView實現(xiàn)表格的方法,文中對Layout_weight屬性先有一個較為詳細的解釋,需要的朋友可以參考下2016-04-04
Android studio實現(xiàn)左右滑動切換圖片
這篇文章主要為大家詳細介紹了Android studio實現(xiàn)左右滑動切換圖片,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05
android TextView多行文本(超過3行)使用ellipsize屬性無效問題的解決方法
這篇文章介紹了android TextView多行文本(超過3行)使用ellipsize屬性無效問題的解決方法,有需要的朋友可以參考一下2013-09-09
Android提高之SQLite分頁讀取實現(xiàn)方法
這篇文章主要介紹了Android的SQLite分頁讀取實現(xiàn)方法,在Android項目開發(fā)中非常實用,需要的朋友可以參考下2014-08-08
Android編程使用ListView實現(xiàn)數(shù)據(jù)列表顯示的方法
這篇文章主要介紹了Android編程使用ListView實現(xiàn)數(shù)據(jù)列表顯示的方法,實例分析了Android中ListView控件的使用技巧,需要的朋友可以參考下2016-01-01
Android自定義View實現(xiàn)比賽時間閃動效果
這篇文章主要為大家詳細介紹了Android自定義View實現(xiàn)比賽時間閃動效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-03-03
Android?Studio打包?aar實現(xiàn)步驟示例詳解
這篇文章主要為大家介紹了Android?Studio打包aar步驟示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08

