android studio使用高德地圖

NO IMAGE
1 Star2 Stars3 Stars4 Stars5 Stars 給文章打分!
Loading...

1、build.gradle(module)加入如下依賴

    compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.amap.api:3dmap:5.1.0'
compile 'com.amap.api:location:3.3.0'
compile 'com.amap.api:search:5.0.0'

2、buld.gradle(project)確保有如下聯網下載依賴的設定

allprojects {
repositories {
google()
jcenter()
}
}

3、佈局檔案加入如下地圖view

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.amap.api.maps.TextureMapView
android:id="@ id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.constraint.ConstraintLayout>

4、activity檔案操作地圖

public class Main_layout extends Activity{
private TextureMapView mMapView;
AMap aMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
//獲取地圖控制元件引用
mMapView = (TextureMapView) findViewById(R.id.map);
//在activity執行onCreate時執行mMapView.onCreate(savedInstanceState),建立地圖
mMapView.onCreate(savedInstanceState);
}
@Override
protected void onDestroy() {
super.onDestroy();
//在activity執行onDestroy時執行mMapView.onDestroy(),銷燬地圖
mMapView.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
//在activity執行onResume時執行mMapView.onResume (),重新繪製載入地圖
mMapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
//在activity執行onPause時執行mMapView.onPause (),暫停地圖的繪製
mMapView.onPause();
}
@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
//在activity執行onSaveInstanceState時執行mMapView.onSaveInstanceState (outState),儲存地圖當前的狀態
mMapView.onSaveInstanceState(savedInstanceState);
}

相關文章

程式語言 最新文章