compile files('libs/BaiduLBS_Android.jar')
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'java
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
<!-- 這個權限用於進行網絡定位 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- 這個權限用於訪問GPS定位 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- 用於訪問wifi網絡信息,wifi信息會用於進行網絡定位 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- 獲取運營商信息,用於支持提供運營商信息相關的接口 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- 用於讀取手機當前的狀態 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!-- 寫入擴展存儲,向擴展卡寫入數據,用於寫入離線定位數據 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- 訪問網絡,網絡定位須要上網 -->
<uses-permission android:name="android.permission.INTERNET"/>android
//本身寫 android:name=".application.MyApplication"api
<application
android:name=".application.MyApplication"
android:allowBackup="true">網絡
package net.bwie.baidumap.application; import android.app.Application; import com.baidu.mapapi.SDKInitializer; public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); //在使用SDK各組件以前初始化context信息,傳入ApplicationContext //注意該方法要再setContentView方法以前實現 SDKInitializer.initialize(getApplicationContext()); } }
package net.bwie.baidumap.activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import net.bwie.baidumap.R; public class BaseMapActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base_map); } }
package net.bwie.baidumap.activity; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import net.bwie.baidumap.R; public class MainActivity extends AppCompatActivity implements View.OnClickListener { protected Button mBaseMapBtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.activity_main); initView(); } @Override public void onClick(View view) { Intent intent = new Intent(); if (view.getId() == R.id.base_map_btn) { intent.setClass(this, BaseMapActivity.class); } startActivity(intent); } private void initView() { mBaseMapBtn = (Button) findViewById(R.id.base_map_btn); mBaseMapBtn.setOnClickListener(MainActivity.this); } }