文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

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

2022-06-06 06:57

关注

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

以下为初次接触时 ,练手的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(); 
} 
 
private void init() { 
if (aMap == null) { 
aMap = mapView.getMap(); 
setUpMap(); 
} 
} 
 
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(); 
} 
 
@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, 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关键字搜索 
===================================================== 
 
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(); //增加数据到数据库 
} 
} 
 
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(); 
} 
 
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); 
} 
 
@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 仿高德地图可拉伸的BottomSheet的示例代码Android基于高德地图完全自定义Marker的实现方法Android调用高德地图定位的方法Android基于高德地图poi的仿微信获取位置功能实例代码Android 高德地图之poi搜索功能的实现代码Android高德地图poi检索仿微信发送位置实例代码Android开发之高德地图实现定位Android之高德地图定位SDK集成及地图功能实现Android中GPS坐标转换为高德地图坐标详解Android实现高德地图显示及定位


阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-移动开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯