亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > Android > 正文

Android之高德地圖定位SDK集成及地圖功能實現

2019-12-12 03:10:08
字體:
來源:轉載
供稿:網友

一:百度高德官方網站,然后去創建應用

網址:http://lbs.amap.com/

1.找到控制臺創建一個應用

2.添加key名稱,注意命名規范,還有就是下面的SHA1和包名

3.點擊右邊的Gradle再選擇signingReport下面會有個命令,稍等幾分鐘得到SHA1

4.添加包名

5.得到key

二:下載定位SDK,下載下來有地圖SDK和定位SDK,然后導入項目,導入再Add As Library,so文件按自己需求來

下載地址:http://lbs.amap.com/api/android-location-sdk/download/

三:在AndroidManifest.xml的application下配置key和注冊service

<!--高德appkey--><meta-data android:name="com.amap.api.v2.apikey" android:value="你的key" /><!--高德service--><service android:name="com.amap.api.location.APSService" />

四:添加權限

<!--高德權限--><!--地圖包、搜索包需要的基礎權限--><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.READ_PHONE_STATE" /><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /><!--定位包、導航包需要的額外權限(注:基礎權限也需要)--><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /><uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /><uses-permission android:name="android.permission.CHANGE_CONFIGURATION" /><uses-permission android:name="android.permission.WRITE_SETTINGS" />

五:地圖xml布局實現

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout  android:id="@+id/layout_bottom"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:layout_alignParentBottom="true"  android:background="@color/textview_qianhui"  android:orientation="vertical"  android:padding="5dp"  android:visibility="gone">  <TextView   android:id="@+id/map_shop_name"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:padding="5dp"   android:text="西貝莜面村(豐臺店)"   android:textSize="16sp" />  <TextView   android:id="@+id/map_shop_address"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:padding="5dp"   android:text="豐葆路,永旺夢樂城四樓" />  <LinearLayout   android:id="@+id/map_shop_goto"   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:layout_gravity="center"   android:gravity="center"   android:orientation="horizontal"   android:padding="10dp">   <TextView    android:id="@+id/map_my_address11"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:background="@color/map_button_color"    android:gravity="center"    android:padding="5dp"    android:text="我的位置"    android:textSize="16sp" />   <TextView    android:id="@+id/map_goto_address11"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_marginLeft="40dp"    android:background="@color/map_button_color"    android:gravity="center"    android:padding="5dp"    android:text="開啟導航"    android:textSize="16sp" />  </LinearLayout> </LinearLayout> <LinearLayout  android:id="@+id/layout_bottom_new"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:layout_alignParentBottom="true"  android:background="@color/map_button_color"  android:orientation="vertical"  android:padding="5dp"  android:visibility="gone">  <TextView   android:id="@+id/tv_getLat"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_weight="1"   android:padding="5dp"   android:text="當前經度:"   android:textSize="16sp" />  <View   android:layout_width="match_parent"   android:layout_height="1dp"   android:background="@color/textview_hui" />  <TextView   android:id="@+id/tv_getLon"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:layout_weight="1"   android:padding="5dp"   android:text="當前緯度:"   android:textSize="16sp" /> </LinearLayout> <com.amap.api.maps.MapView  android:id="@+id/map"  android:layout_width="fill_parent"  android:layout_height="fill_parent"  android:layout_above="@id/layout_bottom_new"  android:clickable="true"  android:enabled="true" /> <ImageView  android:id="@+id/img_back"  android:layout_width="30dp"  android:layout_height="30dp"  android:layout_marginLeft="10dp"  android:layout_marginTop="20dp"  android:background="@mipmap/map_back" /> <ImageView  android:id="@+id/img_save"  android:layout_width="30dp"  android:layout_height="30dp"  android:layout_alignParentRight="true"  android:layout_marginRight="10dp"  android:layout_marginTop="20dp"  android:background="@mipmap/save"  android:visibility="gone" /> <ImageView  android:id="@+id/map_my_address"  android:layout_width="30dp"  android:layout_height="30dp"  android:layout_alignBottom="@id/map"  android:layout_marginBottom="60dp"  android:layout_marginLeft="10dp"  android:background="@mipmap/my_address" /></RelativeLayout>

六:地圖activity實現

package com.zjtd.bzcommunity.map;import android.graphics.BitmapFactory;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.view.View;import android.widget.ImageView;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.MapView;import com.amap.api.maps.model.BitmapDescriptor;import com.amap.api.maps.model.BitmapDescriptorFactory;import com.amap.api.maps.model.LatLng;import com.amap.api.maps.model.MarkerOptions;import com.zjtd.bzcommunity.R;import java.text.SimpleDateFormat;import java.util.Date;/** * Created by Administrator on 2017/3/23. * 高德地圖 */public class ShowMapActivity extends AppCompatActivity implements View.OnClickListener { private MapView mapView;//地圖控件 private ImageView img_back;//返回鍵 private ImageView map_my_address;//復位 private AMap aMap;//地圖控制器對象 //聲明AMapLocationClient類對象 public AMapLocationClient mLocationClient = null; //聲明mLocationOption對象 public AMapLocationClientOption mLocationOption = null; private double lat; private double lon; @Override protected void onCreate(@Nullable Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.map);  initlayout();  //初始化定位  mLocationClient = new AMapLocationClient(getApplicationContext());  //設置定位回調監聽  mLocationClient.setLocationListener(mLocationListener);  //必須要寫  mapView.onCreate(savedInstanceState);  init(); } /**  * 實例化  */ private void initlayout() {  mapView = (MapView) findViewById(R.id.map);  img_back = (ImageView) findViewById(R.id.img_back);  map_my_address = (ImageView) findViewById(R.id.map_my_address);  img_back.setOnClickListener(this);  map_my_address.setOnClickListener(this); } /**  * * 初始化AMap對象  */ private void init() {  if (aMap == null) {   aMap = mapView.getMap();  }  setUpMap(); } /**  * 配置定位參數  */ private void setUpMap() {  //初始化定位參數  mLocationOption = new AMapLocationClientOption();  //設置定位模式為高精度模式,Battery_Saving為低功耗模式,Device_Sensors是僅設備模式  mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);  //設置是否返回地址信息(默認返回地址信息)  mLocationOption.setNeedAddress(true);  //設置是否只定位一次,默認為false  mLocationOption.setOnceLocation(false);  //設置是否強制刷新WIFI,默認為強制刷新  mLocationOption.setWifiActiveScan(true);  //設置是否允許模擬位置,默認為false,不允許模擬位置  mLocationOption.setMockEnable(false);  //設置定位間隔,單位毫秒,默認為2000ms  mLocationOption.setInterval(2000);  //給定位客戶端對象設置定位參數  mLocationClient.setLocationOption(mLocationOption);  //啟動定位  mLocationClient.startLocation(); } /**  * 聲明定位回調監聽器  */ public AMapLocationListener mLocationListener = new AMapLocationListener() {  @Override  public void onLocationChanged(AMapLocation amapLocation) {   if (amapLocation != null) {    if (amapLocation.getErrorCode() == 0) {     //定位成功回調信息,設置相關消息     amapLocation.getLocationType();//獲取當前定位結果來源,如網絡定位結果,詳見定位類型表     amapLocation.getLatitude();//獲取緯度     amapLocation.getLongitude();//獲取經度     amapLocation.getAccuracy();//獲取精度信息     SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");     Date date = new Date(amapLocation.getTime());     df.format(date);//定位時間     amapLocation.getAddress();//地址,如果option中設置isNeedAddress為false,則沒有此結果,網絡定位結果中會有地址信息,GPS定位不返回地址信息。     amapLocation.getCountry();//國家信息     amapLocation.getProvince();//省信息     amapLocation.getCity();//城市信息     amapLocation.getDistrict();//城區信息     amapLocation.getStreet();//街道信息     amapLocation.getStreetNum();//街道門牌號信息     amapLocation.getCityCode();//城市編碼     amapLocation.getAdCode();//地區編碼     amapLocation.getAoiName();//獲取當前定位點的AOI信息     lat = amapLocation.getLatitude();     lon = amapLocation.getLongitude();     Log.v("pcw", "lat : " + lat + " lon : " + lon);     Log.v("pcw", "Country : " + amapLocation.getCountry() + " province : " + amapLocation.getProvince() + " City : " + amapLocation.getCity() + " District : " + amapLocation.getDistrict());     //清空緩存位置     aMap.clear();     // 設置當前地圖顯示為當前位置     aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lon), 19));     MarkerOptions markerOptions = new MarkerOptions();     markerOptions.position(new LatLng(lat, lon));     markerOptions.title("當前位置");     markerOptions.visible(true);     BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.btn_kuaisong_change_icon));     markerOptions.icon(bitmapDescriptor);     aMap.addMarker(markerOptions);    } else {     //顯示錯誤信息ErrCode是錯誤碼,errInfo是錯誤信息,詳見錯誤碼表。     Log.e("AmapError", "location Error, ErrCode:"       + amapLocation.getErrorCode() + ", errInfo:"       + amapLocation.getErrorInfo());    }   }  } }; /**  * 重新繪制加載地圖  */ @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 void onClick(View view) {  switch (view.getId()) {   case R.id.img_back:    finish();    break;  } }}

效果圖:

七:定位功能實現

1.效果圖

2.activity的實現

public class LoginAndRegisterActivity extends Activity implements OnClickListener { /**  * 登錄界面  */ private EditText et_login_phoneNumber;//手機號 private EditText et_login_password;//密碼 private RelativeLayout btn_login;//登錄 private TextView tv_forget;//忘記密碼 private TextView textzc;//注冊 private ImageView imagqk;//清空密碼 private String address;//地址 private LinearLayout lineargg;//隨便逛逛 private ImageView fanhuicc;//返回鍵Register //聲明AMapLocationClient類對象 public AMapLocationClient mLocationClient = null; //聲明定位回調監聽器 //可以通過類implement方式實現AMapLocationListener接口,也可以通過創造接口類對象的方法實現 public AMapLocationListener mLocationListener = new AMapLocationListener() {  @Override  public void onLocationChanged(AMapLocation amapLocation) {   if (amapLocation != null) {    if (amapLocation.getErrorCode() == 0) {     //可在其中解析amapLocation獲取相應內容。     amapLocation.getLocationType();//獲取當前定位結果來源,如網絡定位結果,詳見定位類型表     amapLocation.getLatitude();//獲取緯度     amapLocation.getLongitude();//獲取經度     amapLocation.getAccuracy();//獲取精度信息     amapLocation.getAddress();//地址,如果option中設置isNeedAddress為false,則沒有此結果,網絡定位結果中會有地址信息,GPS定位不返回地址信息。     amapLocation.getCountry();//國家信息     amapLocation.getProvince();//省信息     amapLocation.getCity();//城市信息     amapLocation.getDistrict();//城區信息     amapLocation.getStreet();//街道信息     amapLocation.getStreetNum();//街道門牌號信息     amapLocation.getCityCode();//城市編碼     amapLocation.getAdCode();//地區編碼     amapLocation.getAoiName();//獲取當前定位點的AOI信息     amapLocation.getBuildingId();//獲取當前室內定位的建筑物Id     amapLocation.getFloor();//獲取當前室內定位的樓層//     amapLocation.getGpsStatus();//獲取GPS的當前狀態     //獲取定位時間     SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");     Date date = new Date(amapLocation.getTime());     df.format(date);     address = amapLocation.getAddress();    } else {     //定位失敗時,可通過ErrCode(錯誤碼)信息來確定失敗的原因,errInfo是錯誤信息,詳見錯誤碼表。     Log.e("AmapError", "location Error, ErrCode:"       + amapLocation.getErrorCode() + ", errInfo:"       + amapLocation.getErrorInfo());    }   }  } }; //聲明AMapLocationClientOption對象 public AMapLocationClientOption mLocationOption = null; @Override protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.fragment_login);  initViews();  init(); } /**  * 實例化  */ private void initViews() {  et_login_phoneNumber = (EditText) findViewById(R.id.et_login_phoneNumber);  et_login_password = (EditText) findViewById(R.id.et_login_password);  btn_login = (RelativeLayout) findViewById(R.id.btn_login);  tv_forget = (TextView) findViewById(R.id.tv_forget);  textzc = (TextView) findViewById(R.id.textzc);  imagqk = (ImageView) findViewById(R.id.imagqk);  lineargg = (LinearLayout) findViewById(R.id.lineargg);  fanhuicc = (ImageView) findViewById(R.id.fanhuicc);  btn_login.setOnClickListener(this);  tv_forget.setOnClickListener(this);  textzc.setOnClickListener(this);  imagqk.setOnClickListener(this);  lineargg.setOnClickListener(this);  fanhuicc.setOnClickListener(this); } private void init() {  //初始化定位  mLocationClient = new AMapLocationClient(getApplicationContext());  //設置定位回調監聽  mLocationClient.setLocationListener(mLocationListener);  //初始化AMapLocationClientOption對象  mLocationOption = new AMapLocationClientOption();  //設置定位模式為AMapLocationMode.Hight_Accuracy,高精度模式。  mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);  //設置是否返回地址信息(默認返回地址信息)  mLocationOption.setNeedAddress(true);  //設置是否只定位一次,默認為false  mLocationOption.setOnceLocation(false);  //設置是否強制刷新WIFI,默認為強制刷新  mLocationOption.setWifiActiveScan(true);  //設置是否允許模擬位置,默認為false,不允許模擬位置  mLocationOption.setMockEnable(false);  //設置定位間隔,單位毫秒,默認為2000ms  mLocationOption.setInterval(2000);  //給定位客戶端對象設置定位參數  mLocationClient.setLocationOption(mLocationOption);  //單位是毫秒,默認30000毫秒,建議超時時間不要低于8000毫秒。  mLocationOption.setHttpTimeOut(20000);  //關閉緩存機制  mLocationOption.setLocationCacheEnable(false);  //啟動定位  mLocationClient.startLocation(); }@Overrideprotected void onStop() { super.onStop(); mLocationClient.stopLocation();//停止定位 }/** * 方法必須重寫  */@Overrideprotected void onDestroy() { super.onDestroy(); mLocationClient.onDestroy();//銷毀定位客戶端。 }

到此定位和地圖顯示功能已實現,大神勿噴,有用的可以借鑒一下。

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产精品av在线播放| 国产精品色午夜在线观看| 亚洲国产精品热久久| 国产精品99一区| 国内揄拍国内精品少妇国语| 亚洲综合成人婷婷小说| 欧美交受高潮1| 国产一区二区丝袜高跟鞋图片| 亚洲欧美制服另类日韩| 亚洲精品中文字幕有码专区| 日韩资源在线观看| 国产91精品不卡视频| 亚洲资源在线看| 亚洲精品理论电影| 国产做受69高潮| 国产精品日日摸夜夜添夜夜av| 国产狼人综合免费视频| 欧美激情第1页| 久久久久久久一区二区三区| 久久久免费高清电视剧观看| 97碰碰碰免费色视频| 久久久91精品国产一区不卡| 亚洲精品中文字幕有码专区| 91欧美日韩一区| 国产精品无码专区在线观看| 日韩欧美在线视频| 午夜精品久久久99热福利| 欧美日韩精品在线| 九九九久久国产免费| 精品国产福利视频| 欧美成人性色生活仑片| 成人做爽爽免费视频| 欧美日韩aaaa| 日韩在线观看网站| 国产一区二区三区免费视频| 亚洲一二在线观看| 欧美激情在线一区| 性色av一区二区三区红粉影视| 亚洲男人av在线| 久久久久久伊人| 成人动漫网站在线观看| 久久成人综合视频| 国产91网红主播在线观看| 红桃视频成人在线观看| 欧美大片免费看| 亚洲天堂男人的天堂| 国产精品久久久久久亚洲调教| 日韩精品在线免费| 欧美日韩免费区域视频在线观看| 九九热精品视频| 亚洲福利影片在线| 91精品在线影院| 亚洲人在线视频| 精品久久久久久久久中文字幕| 久久久国产影院| 精品久久久久久久久久国产| 久久久女女女女999久久| 一本一本久久a久久精品牛牛影视| 66m—66摸成人免费视频| 国产精品毛片a∨一区二区三区|国| 亚洲乱码av中文一区二区| 国产九九精品视频| 日韩视频免费在线| 亚洲综合一区二区不卡| 日韩欧美成人区| 国产大片精品免费永久看nba| 北条麻妃一区二区三区中文字幕| 亚洲国产成人久久| 日本一区二三区好的精华液| 自拍偷拍亚洲一区| 久久久久久久久久久免费精品| 欧美电影在线播放| 欧美另类精品xxxx孕妇| 国产精品人成电影| 伊人男人综合视频网| 国产精品久久久久av| 亚洲最大的免费| 亚洲美女黄色片| 国内精品久久久久| 日韩精品在线观看一区| 久久国产精品首页| 91av成人在线| 久久天堂av综合合色| 中文字幕久久久| 亚洲精品xxx| 在线视频欧美日韩| 这里只有精品在线播放| 色樱桃影院亚洲精品影院| 美女福利精品视频| 亚洲国产成人久久综合一区| 1769国内精品视频在线播放| 亚洲电影免费观看| 日韩美女在线看| 欧美精品性视频| 亚洲精品久久视频| 91精品国产乱码久久久久久久久| 国产精品久久久久久av下载红粉| 亚洲精品美女在线| 亚洲国语精品自产拍在线观看| 成人在线视频福利| 欧美亚洲在线视频| 色悠悠久久88| 日韩国产欧美精品一区二区三区| 久久影视电视剧免费网站| 大胆欧美人体视频| 日韩成人小视频| 欧美亚洲另类视频| 日本免费一区二区三区视频观看| 国产精品视频久久久| 亚洲欧洲激情在线| 亚洲乱码一区二区| 欧美成年人视频网站欧美| 亚洲黄色有码视频| 91久久精品在线| 日韩欧美国产中文字幕| 欧美激情视频在线| 日韩精品黄色网| 日韩一区二区三区国产| 国产精品白嫩初高中害羞小美女| 日韩毛片在线看| 亚洲片在线观看| 欧美老少配视频| 色综合影院在线| 久久久999精品免费| 日韩成人在线观看| 福利一区福利二区微拍刺激| 国产精品欧美一区二区三区奶水| 国产成人一区二区三区| 国产一区欧美二区三区| 热草久综合在线| 欧美老女人xx| 国产日韩换脸av一区在线观看| 久久久久久噜噜噜久久久精品| 欧美中文字幕视频在线观看| 亚洲女同精品视频| 中文字幕精品国产| 成人福利在线观看| 久久精品国产一区| 亚洲成人av片| 91精品免费视频| 国产成人精品在线观看| 欧美成人在线免费视频| 亚洲欧洲中文天堂| 成人免费视频网址| 国内精品模特av私拍在线观看| 91亚洲精品在线观看| 欧美夫妻性视频| 欧美日韩xxx| 国产一区二区三区网站| 成人免费激情视频| 美女久久久久久久| 久久成人av网站| 日本伊人精品一区二区三区介绍| 色婷婷久久一区二区| 欧美做受高潮电影o| 亚洲丁香久久久| 欧美日韩福利电影| 久久人人爽人人爽人人片av高请| 91成人精品网站| 欧美性猛交xxxxx免费看| 97精品伊人久久久大香线蕉| 美日韩精品免费视频| 国产视频精品在线| 国产丝袜一区二区三区|