关于Android高德地图的简单开发实例代码(DEMO)

关于Android高德地图的简单开发实例代码(DEMO),第1张

概述废话不多说了,直接给大家上干货了。以下为初次接触时,练手的DEMOimportandroid.app.Activity;

废话不多说了,直接给大家上干货了。

以下为初次接触时 ,练手的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 监听数据形成的列表 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,数据返回的List数据源 //====================以下为 *** 作数据库================== private ArrayList<HashMap<String,Object>> MapHistoryList; //=============地图定位控件============== private OnLocationChangedListener mListener; private AMapLocationClIEnt mlocationClIEnt; private AMapLocationClIEntoption mLocationoption; //=============地图自身UI定义============ private UiSettings mUiSettings; //=============通用地图控件============== private LatLonPoint mLatLonPoint;//初始定位经纬度 private double ms,me; //经纬度double值 private String locationAdressname; //=============地图POI关键字搜索========== private PoiResult poiResult; // poi返回的结果 private PoiSearch.query query;// Poi查询条件类 private PoiSearch poiSearch;// POI搜索 private static String keyWord = "";// 要输入的poi搜索关键字 private int currentPage = 0;// 当前页面,从0开始计数 private button bt_search; //搜索POI private MarkerOptions options; //========================以下为地理编码================= private GeocodeSearch geocoderSearch; private static String addressCitydistric; //得到逆地理编码的 市区 @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);// 设置定位监听 aMap.getUiSettings().setMyLocationbuttonEnabled(true);// 设置默认定位按钮是否显示 aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示 隐藏定位层并不可触发定位,默认是false // 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种 aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE); aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(me,ms),14)); //当前 地图镜头界面 (让地图在刚进入时就是这个的话,需要先得到LatLng值即可,待后续修正) mUiSettings= aMap.getUiSettings(); //实例化地图UI设置 mUiSettings.setScaleControlsEnabled(true); //比例尺显示 mUiSettings.setCompassEnabled(false); //指南针不显示 mLocationoption.setGpsFirst(true); //优先返回GPS定位信息 aMap.setonPOIClickListener(this); //POI 点击事件监听 aMap.setonMarkerClickListener(this); geocoderSearch = new GeocodeSearch(this); geocoderSearch.setonGeocodeSearchListener(this); // 注册地理编码监听 } 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(); //设置定位监听 mlocationClIEnt.setLocationListener(this); //设置为高精度定位模式 mLocationoption.setLocationMode (AMapLocationClIEntoption.AMapLocationMode.Hight_Accuracy); //设置定位参数 mlocationClIEnt.setLocationoption(mLocationoption); // 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗, // 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用 stopLocation()方法来取消定位请求 // 在定位结束后,在合适的生命周期调用onDestroy()方法 // 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求, 定位sdk内部会移除 mlocationClIEnt.startLocation(); } } /** * 停止定位 */ @OverrIDe public voID deactivate() { mListener = null; if (mlocationClIEnt != null) { mlocationClIEnt.stopLocation(); mlocationClIEnt.onDestroy(); } mlocationClIEnt = null; } /** * 定位成功后回调函数 */ @OverrIDe public voID onLocationChanged(AMapLocation amapLocation) { if (mListener != null && amapLocation != null) { if (amapLocation != null && amapLocation.getErrorCode() == 0) { mListener.onLocationChanged(amapLocation);// 显示系统小蓝点 Message msg = mHandler.obtainMessage(); //定位成功后,开始hangler更新经纬 度 msg.obj = amapLocation; msg.what = Utils.MSG_LOCATION_FINISH; mHandler.sendMessage(msg); //当前定位后的详细位置(省、市、区、街道信息) 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 改变监听 =================================== @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); //设置=======得到数据监听======= inputTips.requestinputtipsAsyn(); } } @OverrIDe public voID afterTextChanged(Editable editable) { } //=======得到数据监听======= @OverrIDe public voID onGetinputtips(List<Tip> tipList,int rCode) { if (rCode == 1000) {// 正确返回 //监听反馈回来的数据当做ListVIEw数据源 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 产生的列表的 item点击事件 ListvIEw.setonItemClickListener(new AdapterVIEw.OnItemClickListener() { @OverrIDe public voID onItemClick(AdapterVIEw<?> adapterVIEw,VIEw vIEw,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关键字搜索 ===================================================== /** * 显示进度框 */ 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,"请输入搜索关键字"); 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(); //增加数据到数据库 } } /** * 开始进行poi搜索 */ protected voID doSearchquery() { showProgressDialog();// 显示进度框 mlocationClIEnt.stopLocation(); //停止定位 20160812 query = new PoiSearch.query(keyWord,"",Utils.city);// 第一个参数表示搜索字符串第二个参数表示poi搜索类型,第三个参数表示poi搜索区域(空字符串代表全国) query.setPageSize(20);// 设置每页最多返回多少条poiitem query.setPageNum(currentPage);// 设置查第一页 poiSearch = new PoiSearch(this,query); poiSearch.setonPoiSearchListener(this); poiSearch.searchPOIAsyn(); } /** * poi没有搜索到数据,返回一些推荐城市的信息 */ private voID showSuggestCity(List<SuggestionCity> citIEs) { String infomation = "推荐城市\n"; for (int i = 0; i < citIEs.size(); i++) { infomation += "城市名称:" + citIEs.get(i).getCityname() + "城市区号:" + citIEs.get(i).getCityCode() + "城市编码:" + citIEs.get(i).getAdCode() + "\n"; } ToastUtil.show(BaseMapActivity.this,infomation); } /** * POI信息查询回调方法 */ @OverrIDe public voID onPoiSearched(PoiResult result,int rCode) { dissmissprogressDialog();// 隐藏对话框 if (rCode == 1000) { if (result != null && result.getquery() != null) {// 搜索poi的结果 if (result.getquery().equals(query)) {// 是否是同一条 poiResult = result; // 取得搜索到的poiitems有多少页 List<PoiItem> poiItems = poiResult.getPois();// 取得第一页的poiitem数据,页数从数字0开始 List<SuggestionCity> suggestionCitIEs = poiResult .getSearchSuggestionCitys();// 当搜索不到poiitem数据时,会返回含有搜索关键字的城市信息 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,"无返回结果"); } } } else { ToastUtil.show(BaseMapActivity.this,"无返回结果"); } } 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);// 第一个参数表示地址,第 二个参数表示查询城市,中文或者中文全拼,citycode、adcode, geocoderSearch.getFromLocationnameAsyn(query);// 设置同步地理编码请求 } /** * 响应逆地理编码 */ public voID getAddress(final LatLonPoint latLonPoint) { // showDialog(); Regeocodequery query = new Regeocodequery(latLonPoint,200,GeocodeSearch.AMAP);// 第一个参数表示一个Latlng,第二参数表示范围多少米, 第三个参数表示是火系坐标系还是GPS原生坐标系 geocoderSearch.getFromLocationAsyn(query);// 设置同步逆地理编码请求 } /** * 地理编码查询回调 */ @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 = "经纬度值:" + address.getLatLonPoint() + "\n位置描 述:" // + address.getFormatAddress(); } } else { ToastUtil.showerror(this,rCode); } } /** * 逆地理编码回调 */ @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="路径规划" 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="请输入关键字" 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> 代码中相关的工具类,即官方DEMO 中提供的工具类,并没什么改变。。好了,初步的使用就是这样。清单文件中相关权限<!--地图相关权限--> <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> 申请官方相关key ,根据自己androdi studio 上的sha1值和包名来获取<Meta-data androID:name="com.amap.API.v2.APIkey" androID:value="xxxxxxxxxxxxxxxxxxxxxxx" /> 

以上所述是小编给大家介绍的关于AndroID高德地图的简单开发实例代码(DEMO),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

总结

以上是内存溢出为你收集整理的关于Android高德地图的简单开发实例代码(DEMO)全部内容,希望文章能够帮你解决关于Android高德地图的简单开发实例代码(DEMO)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1147768.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存