├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── libs │ ├── BaiduLBS_Android.jar │ └── BaiduNaviSDK_3.3.0.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── wxx │ │ └── map │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── BaiduNaviSDK_3.3.0.png │ │ ├── BaiduNaviSDK_Resource_3.3.0.png │ │ └── channel │ ├── java │ │ └── com │ │ │ └── wxx │ │ │ └── map │ │ │ ├── BNGuideActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── MainActivity__.java │ │ │ ├── MapCar.java │ │ │ ├── MyApplication.java │ │ │ ├── MyOrentationListener.java │ │ │ ├── NavigatinActivity.java │ │ │ ├── TODO │ │ │ ├── adapter │ │ │ ├── ListAdapter.java │ │ │ └── MyAdapter.java │ │ │ ├── bean │ │ │ └── ListData.java │ │ │ ├── http │ │ │ ├── CallServer.java │ │ │ ├── HttpListener.java │ │ │ └── HttpResponseListener.java │ │ │ ├── mvp │ │ │ ├── LoadCompl.java │ │ │ ├── LoadPresetner.java │ │ │ └── OnLoadResult.java │ │ │ ├── utils │ │ │ └── API.java │ │ │ └── widget │ │ │ ├── ImageTextView.java │ │ │ ├── ListDialog.java │ │ │ └── ZoomControView.java │ ├── jniLibs │ │ ├── arm64-v8a │ │ │ ├── libBaiduMapSDK_base_v4_2_1.so │ │ │ ├── libBaiduMapSDK_map_v4_2_1.so │ │ │ └── liblocSDK7a.so │ │ ├── armeabi │ │ │ ├── libBDSpeechDecoder_V1.so │ │ │ ├── libBaiduMapSDK_base_v4_2_1.so │ │ │ ├── libBaiduMapSDK_map_v4_2_1.so │ │ │ ├── libapp_BaiduNaviApplib.so │ │ │ ├── libapp_BaiduVIlib.so │ │ │ ├── libaudiomessage-jni.so │ │ │ ├── libbd_etts.so │ │ │ ├── libbds.so │ │ │ ├── libbdtts.so │ │ │ ├── libcurl.so │ │ │ ├── libetts_domain_data_builder.so │ │ │ ├── libgnustl_shared.so │ │ │ ├── liblocSDK7a.so │ │ │ └── liblocnaviSDK.so │ │ ├── x86 │ │ │ ├── libBaiduMapSDK_base_v4_2_1.so │ │ │ ├── libBaiduMapSDK_map_v4_2_1.so │ │ │ └── liblocSDK7a.so │ │ └── x86_64 │ │ │ ├── libBaiduMapSDK_base_v4_2_1.so │ │ │ ├── libBaiduMapSDK_map_v4_2_1.so │ │ │ └── liblocSDK7a.so │ └── res │ │ ├── anim │ │ ├── push_bottom_in.xml │ │ └── push_bottom_out.xml │ │ ├── drawable │ │ ├── enlarge_selector.xml │ │ ├── list_selector.xml │ │ ├── location_selector.xml │ │ ├── narrow_selector.xml │ │ ├── roadlingt_selector.xml │ │ ├── scale_item_normal.xml │ │ ├── search_selector.xml │ │ ├── selector_recycler_item.xml │ │ └── text_line.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_main_custom.xml │ │ ├── item.xml │ │ ├── item_zoom.xml │ │ ├── list_item_view.xml │ │ ├── list_main.xml │ │ └── popu_view.xml │ │ ├── menu │ │ └── activity_menu.xml │ │ ├── mipmap-hdpi │ │ ├── arrow_green_direction.png │ │ ├── ic_dh.png │ │ ├── ic_homepage_list.png │ │ ├── ic_homepage_list_pressed.png │ │ ├── ic_homepage_search.png │ │ ├── ic_homepage_search_pressed.png │ │ ├── ic_launcher.png │ │ ├── ic_location.png │ │ └── ic_mn.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_bun_store.png │ │ ├── ic_handle.jpg │ │ ├── ic_homepage_roadlight.png │ │ ├── ic_homepage_roadlight_pressed.png │ │ ├── ic_homepage_target.png │ │ ├── ic_homepage_target_pressed.png │ │ ├── ic_homepage_zoomin.png │ │ ├── ic_homepage_zoomin_pressed.png │ │ ├── ic_homepage_zoomout.png │ │ ├── ic_homepage_zoomout_pressed.png │ │ ├── ic_launcher.png │ │ ├── ic_mb.png │ │ ├── ic_notification.png │ │ ├── ic_scanpay.png │ │ ├── ic_user.png │ │ ├── ic_vipcard.png │ │ ├── ic_wecarmall.png │ │ ├── location_tips.9.png │ │ └── navi_map_gps_locked.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── wxx │ └── map │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img ├── ic_001.png ├── ic_002.png ├── ic_003.png ├── ic_004.png └── ic_005.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BaiduMap 2 | ## 1.jar包+so库的引用 3 | 初始化(在setConView()之前调用,建议在application)
4 | SDKInitializer.initialize(getApplicationContext());
5 | 6 | MapStatusUpdate status = MapStatusUpdateFactory.zoomTo(15.0F);
7 | mBaiduMap.setMapStatus(status);
8 | 9 | ## 2.加入定位,集成方向传感器 10 | LocationClient
11 | LocationClientOption定位的一些设置
12 | BDLocationListener
13 | BDLocation
14 | MyLocationData
15 | 自定义图标
16 | BitmapDescriptor
17 | 引入方向传感器
18 | SensorManager-Sensor
19 | BDLocationListener对方向进行设置
20 | 21 | ## 3.模式切换
22 | mLocationMode:三种模式,NORMAL、FOLLOWING、COMPASS(圆盘,实时定位)
23 | MyLocationConfiguration config = new MyLocationConfiguration(mLocationMode, true, mLoacationBitmap);
24 | mBaiduMap.setMyLocationConfigeration(config);
25 | 26 | ## 4.添加覆盖物,覆盖物的点击事件以及InfoWindow
27 | Marker:覆盖物标示
28 | OverlayOptions 指定位置坐标
29 | Baidumap.setOnMarerClickListener
30 | InfoWindow:BaiduMap.showInfowindow,BaiduMap.hideInfoWindow
31 | 32 | 33 | ## 5.事件 34 | //覆盖物的点击事件
35 | mBaiduMap.setOnMarkerClickListener(this);
36 | //地图的点击事件
37 | mBaiduMap.setOnMapClickListener(this);
38 | //地图状态事件
39 | mBaiduMap.setOnMapStatusChangeListener(this);
40 | ## 6.添加导航 41 | 注意:
42 | 1).删除armeabi-v7a so包才会验证成功,无fuck说
43 | 2).TTS白名单注册(否认无导播声音)
44 | 3).权限问题
45 | 初始化导航
46 | BaiduNaviManager.getInstance().init(this, mSDCardPath, APP_FOLDER_NAME, new BaiduNaviManager.NaviInitListener……
47 | 设置导播声音
48 | Bundle bundle = new Bundle();
49 | // 必须设置APPID,否则会静音
50 | bundle.putString(BNCommonSettingParam.TTS_APP_ID, "0F5B74755E163F0570459A939D1DF18E");
51 | BNaviSettingManager.setNaviSdkParam(bundle);
52 | 53 | ## 预览 54 |
55 | 56 |
57 | 58 |
59 | 60 |
61 | 62 |
63 | 64 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.jakewharton.butterknife' 3 | 4 | android { 5 | compileSdkVersion 24 6 | buildToolsVersion "25.0.2" 7 | defaultConfig { 8 | applicationId "com.wxx.map" 9 | minSdkVersion 15 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(include: ['*.jar'], dir: 'libs') 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | compile 'com.android.support:appcompat-v7:24.2.1' 29 | testCompile 'junit:junit:4.12' 30 | compile files('libs/BaiduLBS_Android.jar') 31 | compile 'com.android.support:design:24.2.1' 32 | compile 'com.jakewharton:butterknife:8.4.0' 33 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' 34 | compile files('libs/BaiduNaviSDK_3.3.0.jar') 35 | compile 'com.google.code.gson:gson:2.2.4' 36 | compile 'com.yanzhenjie.nohttp:okhttp:1.1.1' 37 | compile 'com.android.support:cardview-v7:24.2.1' 38 | } 39 | -------------------------------------------------------------------------------- /app/libs/BaiduLBS_Android.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/libs/BaiduLBS_Android.jar -------------------------------------------------------------------------------- /app/libs/BaiduNaviSDK_3.3.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/libs/BaiduNaviSDK_3.3.0.jar -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Users\Tangren_\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/wxx/map/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.wxx.map", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 38 | 39 | 42 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /app/src/main/assets/BaiduNaviSDK_3.3.0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/assets/BaiduNaviSDK_3.3.0.png -------------------------------------------------------------------------------- /app/src/main/assets/BaiduNaviSDK_Resource_3.3.0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/assets/BaiduNaviSDK_Resource_3.3.0.png -------------------------------------------------------------------------------- /app/src/main/assets/channel: -------------------------------------------------------------------------------- 1 | baidu -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/BNGuideActivity.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map; 2 | 3 | import android.content.Intent; 4 | import android.os.Build; 5 | import android.os.Bundle; 6 | import android.os.Handler; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.util.Log; 9 | import android.view.View; 10 | 11 | import com.baidu.navisdk.adapter.BNRouteGuideManager; 12 | import com.baidu.navisdk.adapter.BNRouteGuideManager.CustomizedLayerItem; 13 | import com.baidu.navisdk.adapter.BNRouteGuideManager.OnNavigationListener; 14 | import com.baidu.navisdk.adapter.BNRoutePlanNode; 15 | import com.baidu.navisdk.adapter.BNRoutePlanNode.CoordinateType; 16 | import com.baidu.navisdk.adapter.BNaviBaseCallbackModel; 17 | import com.baidu.navisdk.adapter.BaiduNaviCommonModule; 18 | import com.baidu.navisdk.adapter.NaviModuleFactory; 19 | import com.baidu.navisdk.adapter.NaviModuleImpl; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | /** 25 | * 诱导界面 26 | * 27 | * @author sunhao04 28 | */ 29 | public class BNGuideActivity extends AppCompatActivity { 30 | 31 | private final String TAG = BNGuideActivity.class.getName(); 32 | private BNRoutePlanNode mBNRoutePlanNode = null; 33 | private BaiduNaviCommonModule mBaiduNaviCommonModule = null; 34 | 35 | /* 36 | * 对于导航模块有两种方式来实现发起导航。 1:使用通用接口来实现 2:使用传统接口来实现 37 | * 38 | */ 39 | // 是否使用通用接口 40 | private boolean useCommonInterface = true; 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | 46 | MainActivity.activityList.add(this); 47 | createHandler(); 48 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 49 | } 50 | View view = null; 51 | if (useCommonInterface) { 52 | //使用通用接口 53 | mBaiduNaviCommonModule = NaviModuleFactory.getNaviModuleManager().getNaviCommonModule( 54 | NaviModuleImpl.BNaviCommonModuleConstants.ROUTE_GUIDE_MODULE, this, 55 | BNaviBaseCallbackModel.BNaviBaseCallbackConstants.CALLBACK_ROUTEGUIDE_TYPE, mOnNavigationListener); 56 | if (mBaiduNaviCommonModule != null) { 57 | mBaiduNaviCommonModule.onCreate(); 58 | view = mBaiduNaviCommonModule.getView(); 59 | } 60 | 61 | } else { 62 | //使用传统接口 63 | view = BNRouteGuideManager.getInstance().onCreate(this, mOnNavigationListener); 64 | } 65 | 66 | 67 | if (view != null) { 68 | setContentView(view); 69 | } 70 | 71 | Intent intent = getIntent(); 72 | if (intent != null) { 73 | Bundle bundle = intent.getExtras(); 74 | if (bundle != null) { 75 | mBNRoutePlanNode = (BNRoutePlanNode) bundle.getSerializable(MainActivity.ROUTE_PLAN_NODE); 76 | } 77 | } 78 | //显示自定义图标 79 | if (hd != null) { 80 | hd.sendEmptyMessageAtTime(MSG_SHOW, 5000); 81 | } 82 | } 83 | 84 | @Override 85 | protected void onResume() { 86 | super.onResume(); 87 | if (useCommonInterface) { 88 | if (mBaiduNaviCommonModule != null) { 89 | mBaiduNaviCommonModule.onResume(); 90 | } 91 | } else { 92 | BNRouteGuideManager.getInstance().onResume(); 93 | } 94 | 95 | 96 | } 97 | 98 | protected void onPause() { 99 | super.onPause(); 100 | 101 | if (useCommonInterface) { 102 | if (mBaiduNaviCommonModule != null) { 103 | mBaiduNaviCommonModule.onPause(); 104 | } 105 | } else { 106 | BNRouteGuideManager.getInstance().onPause(); 107 | } 108 | 109 | } 110 | 111 | ; 112 | 113 | @Override 114 | protected void onDestroy() { 115 | super.onDestroy(); 116 | if (useCommonInterface) { 117 | if (mBaiduNaviCommonModule != null) { 118 | mBaiduNaviCommonModule.onDestroy(); 119 | } 120 | } else { 121 | BNRouteGuideManager.getInstance().onDestroy(); 122 | } 123 | MainActivity.activityList.remove(this); 124 | 125 | } 126 | 127 | @Override 128 | protected void onStop() { 129 | super.onStop(); 130 | if (useCommonInterface) { 131 | if (mBaiduNaviCommonModule != null) { 132 | mBaiduNaviCommonModule.onStop(); 133 | } 134 | } else { 135 | BNRouteGuideManager.getInstance().onStop(); 136 | } 137 | 138 | } 139 | 140 | @Override 141 | public void onBackPressed() { 142 | if (useCommonInterface) { 143 | if (mBaiduNaviCommonModule != null) { 144 | mBaiduNaviCommonModule.onBackPressed(true); 145 | } 146 | } else { 147 | BNRouteGuideManager.getInstance().onBackPressed(false); 148 | } 149 | } 150 | 151 | public void onConfigurationChanged(android.content.res.Configuration newConfig) { 152 | super.onConfigurationChanged(newConfig); 153 | if (useCommonInterface) { 154 | if (mBaiduNaviCommonModule != null) { 155 | mBaiduNaviCommonModule.onConfigurationChanged(newConfig); 156 | } 157 | } else { 158 | BNRouteGuideManager.getInstance().onConfigurationChanged(newConfig); 159 | } 160 | 161 | } 162 | 163 | ; 164 | 165 | 166 | @Override 167 | public boolean onKeyDown(int keyCode, android.view.KeyEvent event) { 168 | if (useCommonInterface) { 169 | if (mBaiduNaviCommonModule != null) { 170 | Bundle mBundle = new Bundle(); 171 | mBundle.putInt(RouteGuideModuleConstants.KEY_TYPE_KEYCODE, keyCode); 172 | mBundle.putParcelable(RouteGuideModuleConstants.KEY_TYPE_EVENT, event); 173 | mBaiduNaviCommonModule.setModuleParams(RouteGuideModuleConstants.METHOD_TYPE_ON_KEY_DOWN, mBundle); 174 | try { 175 | Boolean ret = (Boolean) mBundle.get(RET_COMMON_MODULE); 176 | if (ret) { 177 | return true; 178 | } 179 | } catch (Exception e) { 180 | e.printStackTrace(); 181 | } 182 | } 183 | } 184 | return super.onKeyDown(keyCode, event); 185 | } 186 | 187 | @Override 188 | protected void onStart() { 189 | super.onStart(); 190 | // TODO Auto-generated method stub 191 | if (useCommonInterface) { 192 | if (mBaiduNaviCommonModule != null) { 193 | mBaiduNaviCommonModule.onStart(); 194 | } 195 | } else { 196 | BNRouteGuideManager.getInstance().onStart(); 197 | } 198 | } 199 | 200 | private void addCustomizedLayerItems() { 201 | List items = new ArrayList(); 202 | CustomizedLayerItem item1 = null; 203 | if (mBNRoutePlanNode != null) { 204 | item1 = new CustomizedLayerItem(mBNRoutePlanNode.getLongitude(), mBNRoutePlanNode.getLatitude(), 205 | mBNRoutePlanNode.getCoordinateType(), getResources().getDrawable(R.mipmap.ic_launcher), 206 | CustomizedLayerItem.ALIGN_CENTER); 207 | items.add(item1); 208 | 209 | BNRouteGuideManager.getInstance().setCustomizedLayerItems(items); 210 | } 211 | BNRouteGuideManager.getInstance().showCustomizedLayer(true); 212 | } 213 | 214 | private static final int MSG_SHOW = 1; 215 | private static final int MSG_HIDE = 2; 216 | private static final int MSG_RESET_NODE = 3; 217 | private Handler hd = null; 218 | 219 | private void createHandler() { 220 | if (hd == null) { 221 | hd = new Handler(getMainLooper()) { 222 | public void handleMessage(android.os.Message msg) { 223 | if (msg.what == MSG_SHOW) { 224 | addCustomizedLayerItems(); 225 | } else if (msg.what == MSG_HIDE) { 226 | BNRouteGuideManager.getInstance().showCustomizedLayer(false); 227 | } else if (msg.what == MSG_RESET_NODE) { 228 | BNRouteGuideManager.getInstance().resetEndNodeInNavi( 229 | new BNRoutePlanNode(116.21142, 40.85087, "百度大厦11", null, CoordinateType.GCJ02)); 230 | } 231 | } 232 | 233 | ; 234 | }; 235 | } 236 | } 237 | 238 | private OnNavigationListener mOnNavigationListener = new OnNavigationListener() { 239 | 240 | @Override 241 | public void onNaviGuideEnd() { 242 | //退出导航 243 | finish(); 244 | } 245 | 246 | @Override 247 | public void notifyOtherAction(int actionType, int arg1, int arg2, Object obj) { 248 | 249 | if (actionType == 0) { 250 | //导航到达目的地 自动退出 251 | Log.i(TAG, "notifyOtherAction actionType = " + actionType + ",导航到达目的地!"); 252 | } 253 | 254 | Log.i(TAG, "actionType:" + actionType + "arg1:" + arg1 + "arg2:" + arg2 + "obj:" + obj.toString()); 255 | } 256 | 257 | }; 258 | 259 | private final static String RET_COMMON_MODULE = "module.ret"; 260 | 261 | private interface RouteGuideModuleConstants { 262 | final static int METHOD_TYPE_ON_KEY_DOWN = 0x01; 263 | final static String KEY_TYPE_KEYCODE = "keyCode"; 264 | final static String KEY_TYPE_EVENT = "event"; 265 | } 266 | 267 | 268 | @Override 269 | public void onWindowFocusChanged(boolean hasFocus) { 270 | super.onWindowFocusChanged(hasFocus); 271 | if (hasFocus && Build.VERSION.SDK_INT > 19) { 272 | getWindow().getDecorView() 273 | .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE 274 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 275 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 276 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 277 | | View.SYSTEM_UI_FLAG_FULLSCREEN 278 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); 279 | } 280 | } 281 | } 282 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.content.pm.PackageManager; 7 | import android.graphics.Color; 8 | import android.graphics.Point; 9 | import android.os.Build; 10 | import android.os.Bundle; 11 | import android.os.Environment; 12 | import android.os.Handler; 13 | import android.os.Message; 14 | import android.support.annotation.NonNull; 15 | import android.support.design.widget.BottomSheetBehavior; 16 | import android.support.design.widget.FloatingActionButton; 17 | import android.support.v7.app.AppCompatActivity; 18 | import android.support.v7.widget.DefaultItemAnimator; 19 | import android.support.v7.widget.LinearLayoutManager; 20 | import android.support.v7.widget.RecyclerView; 21 | import android.util.Log; 22 | import android.view.Gravity; 23 | import android.view.Menu; 24 | import android.view.MenuItem; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | import android.view.Window; 28 | import android.view.animation.Animation; 29 | import android.view.animation.TranslateAnimation; 30 | import android.widget.Button; 31 | import android.widget.ImageView; 32 | import android.widget.LinearLayout; 33 | import android.widget.TextView; 34 | import android.widget.Toast; 35 | import android.widget.ZoomControls; 36 | 37 | import com.baidu.location.BDLocation; 38 | import com.baidu.location.BDLocationListener; 39 | import com.baidu.location.LocationClient; 40 | import com.baidu.location.LocationClientOption; 41 | import com.baidu.mapapi.SDKInitializer; 42 | import com.baidu.mapapi.map.BaiduMap; 43 | import com.baidu.mapapi.map.BitmapDescriptor; 44 | import com.baidu.mapapi.map.BitmapDescriptorFactory; 45 | import com.baidu.mapapi.map.InfoWindow; 46 | import com.baidu.mapapi.map.MapPoi; 47 | import com.baidu.mapapi.map.MapStatus; 48 | import com.baidu.mapapi.map.MapStatusUpdate; 49 | import com.baidu.mapapi.map.MapStatusUpdateFactory; 50 | import com.baidu.mapapi.map.MapView; 51 | import com.baidu.mapapi.map.Marker; 52 | import com.baidu.mapapi.map.MarkerOptions; 53 | import com.baidu.mapapi.map.MyLocationConfiguration; 54 | import com.baidu.mapapi.map.MyLocationData; 55 | import com.baidu.mapapi.map.OverlayOptions; 56 | import com.baidu.mapapi.model.LatLng; 57 | import com.baidu.navisdk.adapter.BNCommonSettingParam; 58 | import com.baidu.navisdk.adapter.BNRoutePlanNode; 59 | import com.baidu.navisdk.adapter.BNaviSettingManager; 60 | import com.baidu.navisdk.adapter.BaiduNaviManager; 61 | import com.wxx.map.adapter.MyAdapter; 62 | import com.wxx.map.bean.ListData; 63 | import com.wxx.map.mvp.LoadCompl; 64 | import com.wxx.map.mvp.LoadPresetner; 65 | import com.wxx.map.mvp.OnLoadResult; 66 | import com.wxx.map.widget.ListDialog; 67 | import com.wxx.map.widget.ZoomControView; 68 | 69 | import java.io.File; 70 | import java.util.ArrayList; 71 | import java.util.LinkedList; 72 | import java.util.List; 73 | 74 | import butterknife.BindView; 75 | import butterknife.ButterKnife; 76 | import butterknife.OnClick; 77 | 78 | public class MainActivity extends AppCompatActivity implements BaiduMap.OnMarkerClickListener 79 | , BaiduMap.OnMapClickListener, BaiduMap.OnMapStatusChangeListener, OnLoadResult { 80 | 81 | @BindView(R.id.mMapView) 82 | MapView mMapView; 83 | 84 | private static final String TAG = "MainActivity"; 85 | @BindView(R.id.dh) 86 | FloatingActionButton dh; 87 | @BindView(R.id.mn) 88 | FloatingActionButton mn; 89 | @BindView(R.id.zoom) 90 | ZoomControView zoom; 91 | @BindView(R.id.list) 92 | Button list; 93 | @BindView(R.id.recyclerView) 94 | RecyclerView recyclerView; 95 | @BindView(R.id.linerLayout) 96 | LinearLayout linerLayout; 97 | 98 | private BaiduMap mBaiduMap; 99 | private LocationClient mLocationClient; 100 | private MyLoacationListener myLocationListener; 101 | private boolean isFirstIn = true; 102 | 103 | private double mLatitude; 104 | private double mLongitude; 105 | private BitmapDescriptor mLoacationBitmap; 106 | 107 | private MyOrentationListener myOrentationListener; 108 | private float mCurrentX;//当前位置 109 | 110 | private MyLocationConfiguration.LocationMode mLocationMode; 111 | 112 | //覆盖物 113 | private BitmapDescriptor mMarker; 114 | 115 | //infowindow 116 | private BitmapDescriptor mBitmapWindow; 117 | private InfoWindow infoWindow; 118 | 119 | //显示的动画 120 | private TranslateAnimation shwoAction; 121 | //隐藏时的动画 122 | private TranslateAnimation hideAction; 123 | 124 | //当前选择的经纬度 125 | private LatLng currentLatLng = null; 126 | 127 | //导航相关权限 128 | private static final String[] authBaseArr = {Manifest.permission.WRITE_EXTERNAL_STORAGE, 129 | Manifest.permission.ACCESS_FINE_LOCATION}; 130 | private static final String[] authComArr = {Manifest.permission.READ_PHONE_STATE}; 131 | private static final int authBaseRequestCode = 1; 132 | private static final int authComRequestCode = 2; 133 | private String APP_FOLDER_NAME = "TMap"; 134 | private String mSDCardPath = null; 135 | public static final String ROUTE_PLAN_NODE = "routePlanNode"; 136 | public static List activityList = new LinkedList(); 137 | private boolean hasInitSuccess = false;//百度导航是否初始化成功 138 | private boolean hasRequestComAuth = false; 139 | 140 | //popuwidow 141 | private ListDialog mDialog; 142 | private LoadPresetner mPresenter; 143 | 144 | @Override 145 | protected void onCreate(Bundle savedInstanceState) { 146 | super.onCreate(savedInstanceState); 147 | requestWindowFeature(Window.FEATURE_NO_TITLE); 148 | SDKInitializer.initialize(getApplicationContext()); 149 | setContentView(R.layout.activity_main_custom); 150 | ButterKnife.bind(this); 151 | initView(); 152 | initMarker(); 153 | initLocation(); 154 | 155 | 156 | if (initDirs()) { 157 | initNavigatin(); 158 | } 159 | 160 | } 161 | 162 | String authinfo = null; 163 | 164 | /*************************************** 165 | * 导航部分 166 | ***************************************************/ 167 | private void initNavigatin() { 168 | //申请权限 169 | if (Build.VERSION.SDK_INT >= 23) { 170 | if (!hasBasePhoneAuth()) { 171 | this.requestPermissions(authBaseArr, authBaseRequestCode); 172 | return; 173 | } 174 | } 175 | //初始化导航 176 | BaiduNaviManager.getInstance().init(this, mSDCardPath, APP_FOLDER_NAME, new BaiduNaviManager.NaviInitListener() { 177 | @Override 178 | public void onAuthResult(int status, String msg) { 179 | if (0 == status) { 180 | authinfo = "key校验成功!"; 181 | } else { 182 | authinfo = "key校验失败, " + msg; 183 | } 184 | MainActivity.this.runOnUiThread(new Runnable() { 185 | 186 | @Override 187 | public void run() { 188 | Toast.makeText(MainActivity.this, authinfo, Toast.LENGTH_LONG).show(); 189 | } 190 | }); 191 | } 192 | 193 | @Override 194 | public void initStart() { 195 | Toast.makeText(MainActivity.this, "百度导航初始化开始", Toast.LENGTH_SHORT).show(); 196 | } 197 | 198 | @Override 199 | public void initSuccess() { 200 | Toast.makeText(MainActivity.this, "百度导航初始化成功", Toast.LENGTH_SHORT).show(); 201 | hasInitSuccess = true; 202 | initSetting(); 203 | } 204 | 205 | @Override 206 | public void initFailed() { 207 | Toast.makeText(MainActivity.this, "百度导航引擎初始化失败", Toast.LENGTH_SHORT).show(); 208 | } 209 | }, null, ttsHandler, ttsPlayStateListener); 210 | } 211 | 212 | 213 | /** 214 | * 内部TTS播报状态回传handler 215 | */ 216 | private Handler ttsHandler = new Handler() { 217 | public void handleMessage(Message msg) { 218 | int type = msg.what; 219 | switch (type) { 220 | case BaiduNaviManager.TTSPlayMsgType.PLAY_START_MSG: { 221 | Log.d(TAG, "Handler : TTS play start"); 222 | break; 223 | } 224 | case BaiduNaviManager.TTSPlayMsgType.PLAY_END_MSG: { 225 | Log.d(TAG, "Handler : TTS play end"); 226 | break; 227 | } 228 | default: 229 | showToastMsg("TTS验证失败"); 230 | Log.d(TAG, "TTS验证失败"); 231 | break; 232 | } 233 | } 234 | }; 235 | 236 | private void initSetting() { 237 | // BNaviSettingManager.setDayNightMode(BNaviSettingManager.DayNightMode.DAY_NIGHT_MODE_DAY); 238 | BNaviSettingManager 239 | .setShowTotalRoadConditionBar(BNaviSettingManager.PreViewRoadCondition.ROAD_CONDITION_BAR_SHOW_ON); 240 | BNaviSettingManager.setVoiceMode(BNaviSettingManager.VoiceMode.Veteran); 241 | // BNaviSettingManager.setPowerSaveMode(BNaviSettingManager.PowerSaveMode.DISABLE_MODE); 242 | BNaviSettingManager.setRealRoadCondition(BNaviSettingManager.RealRoadCondition.NAVI_ITS_ON); 243 | Bundle bundle = new Bundle(); 244 | // 必须设置APPID,否则会静音 245 | bundle.putString(BNCommonSettingParam.TTS_APP_ID, "0F5B74755E163F0570459A939D1DF18E"); 246 | Log.d(TAG, "设置APPID"); 247 | BNaviSettingManager.setNaviSdkParam(bundle); 248 | } 249 | 250 | /** 251 | * 内部TTS播报状态回调接口 252 | */ 253 | private BaiduNaviManager.TTSPlayStateListener ttsPlayStateListener = new BaiduNaviManager.TTSPlayStateListener() { 254 | 255 | @Override 256 | public void playEnd() { 257 | Log.d(TAG, "TTSPlayStateListener : TTS play end"); 258 | } 259 | 260 | @Override 261 | public void playStart() { 262 | Log.d(TAG, "TTSPlayStateListener : TTS play start"); 263 | } 264 | }; 265 | 266 | public void showToastMsg(final String msg) { 267 | MainActivity.this.runOnUiThread(new Runnable() { 268 | 269 | @Override 270 | public void run() { 271 | Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 272 | } 273 | }); 274 | } 275 | 276 | //初始化文件路径 277 | private boolean initDirs() { 278 | mSDCardPath = getSdcardDir(); 279 | if (mSDCardPath == null) { 280 | return false; 281 | } 282 | File f = new File(mSDCardPath, APP_FOLDER_NAME); 283 | if (!f.exists()) { 284 | try { 285 | f.mkdir(); 286 | } catch (Exception e) { 287 | e.printStackTrace(); 288 | return false; 289 | } 290 | } 291 | return true; 292 | } 293 | 294 | //判断是否有Sd卡 295 | private String getSdcardDir() { 296 | if (Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { 297 | return Environment.getExternalStorageDirectory().toString(); 298 | } 299 | return null; 300 | } 301 | 302 | 303 | private boolean hasBasePhoneAuth() { 304 | if (Build.VERSION.SDK_INT >= 23) { 305 | PackageManager pm = this.getPackageManager(); 306 | for (String auth : authComArr) { 307 | if (pm.checkPermission(auth, this.getPackageName()) != PackageManager.PERMISSION_GRANTED) { 308 | return false; 309 | } 310 | } 311 | } 312 | return true; 313 | } 314 | 315 | 316 | private void routeplanToNavi(LatLng currentLatLng, boolean isSimulation) { 317 | BNRoutePlanNode.CoordinateType mCoordinateType = BNRoutePlanNode.CoordinateType.BD09LL; 318 | if (!hasInitSuccess) { 319 | Toast.makeText(MainActivity.this, "还未初始化!", Toast.LENGTH_SHORT).show(); 320 | } 321 | // 权限申请 322 | if (Build.VERSION.SDK_INT >= 23) { 323 | // 保证导航功能完备 324 | if (!hasCompletePhoneAuth()) { 325 | if (!hasRequestComAuth) { 326 | hasRequestComAuth = true; 327 | this.requestPermissions(authComArr, authComRequestCode); 328 | return; 329 | } else { 330 | Toast.makeText(MainActivity.this, "没有完备的权限!", Toast.LENGTH_SHORT).show(); 331 | } 332 | } 333 | 334 | } 335 | 336 | BNRoutePlanNode sNode = null; 337 | BNRoutePlanNode eNode = null; 338 | 339 | 340 | // sNode = new BNRoutePlanNode(113.9512500000, 22.5489710000, "出发地", null, mCoordinateType); 341 | // eNode = new BNRoutePlanNode(113.9410840000, 22.5460020000, "终点站", null, mCoordinateType); 342 | 343 | sNode = new BNRoutePlanNode(mLongitude, mLatitude, "起始地", null, mCoordinateType); 344 | eNode = new BNRoutePlanNode(currentLatLng.longitude, currentLatLng.latitude, "目的地", null, mCoordinateType); 345 | 346 | if (sNode != null && eNode != null) { 347 | List list = new ArrayList(); 348 | list.add(sNode); 349 | list.add(eNode); 350 | BaiduNaviManager.getInstance().launchNavigator(this, list, 1, isSimulation, new DemoRoutePlanListener(sNode)); 351 | } 352 | } 353 | 354 | 355 | public class DemoRoutePlanListener implements BaiduNaviManager.RoutePlanListener { 356 | 357 | private BNRoutePlanNode mBNRoutePlanNode = null; 358 | 359 | public DemoRoutePlanListener(BNRoutePlanNode node) { 360 | mBNRoutePlanNode = node; 361 | } 362 | 363 | @Override 364 | public void onJumpToNavigator() { 365 | 366 | //设置途径点以及resetEndNode会回调该接口 367 | 368 | for (Activity ac : activityList) { 369 | if (ac.getClass().getName().endsWith("BNGuideActivity")) { 370 | return; 371 | } 372 | } 373 | Intent intent = new Intent(MainActivity.this, BNGuideActivity.class); 374 | Bundle bundle = new Bundle(); 375 | bundle.putSerializable(ROUTE_PLAN_NODE, (BNRoutePlanNode) mBNRoutePlanNode); 376 | intent.putExtras(bundle); 377 | startActivity(intent); 378 | 379 | } 380 | 381 | @Override 382 | public void onRoutePlanFailed() { 383 | // TODO Auto-generated method stub 384 | Toast.makeText(MainActivity.this, "算路失败", Toast.LENGTH_SHORT).show(); 385 | } 386 | } 387 | 388 | 389 | private boolean hasCompletePhoneAuth() { 390 | // TODO Auto-generated method stub 391 | 392 | PackageManager pm = this.getPackageManager(); 393 | for (String auth : authComArr) { 394 | if (pm.checkPermission(auth, this.getPackageName()) != PackageManager.PERMISSION_GRANTED) { 395 | return false; 396 | } 397 | } 398 | return true; 399 | } 400 | 401 | /*****************************************************************************************/ 402 | private void initMarker() { 403 | mMarker = BitmapDescriptorFactory.fromResource(R.mipmap.ic_mb); 404 | addOverLays(MapCar.infos); 405 | } 406 | 407 | private void initView() { 408 | 409 | shwoAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f, 410 | Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 411 | 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); 412 | shwoAction.setDuration(300); 413 | 414 | hideAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, 415 | Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 416 | 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); 417 | hideAction.setDuration(300); 418 | 419 | 420 | mBaiduMap = mMapView.getMap(); 421 | //隐藏缩放控件 422 | mMapView.showZoomControls(false); 423 | //是否显示比例尺,默认true 424 | mMapView.showScaleControl(true); 425 | zoom.setMapView(mMapView); 426 | //隐藏logo 427 | View child = mMapView.getChildAt(1); 428 | if (child != null && (child instanceof ImageView || child instanceof ZoomControls)) 429 | child.setVisibility(View.GONE); 430 | 431 | //覆盖物的点击事件 432 | mBaiduMap.setOnMarkerClickListener(this); 433 | //地图的点击事件 434 | mBaiduMap.setOnMapClickListener(this); 435 | //地图状态事件 436 | mBaiduMap.setOnMapStatusChangeListener(this); 437 | mBaiduMap.setMyLocationEnabled(true);//开启定位图层 438 | MapStatusUpdate status = MapStatusUpdateFactory.zoomTo(15.0F); 439 | mBaiduMap.setMapStatus(status); 440 | 441 | 442 | //Bottomsheet 443 | 444 | initBottomSheet(); 445 | 446 | 447 | mDialog = new ListDialog(this); 448 | mPresenter = new LoadCompl(this); 449 | } 450 | 451 | private void initBottomSheet() { 452 | final BottomSheetBehavior sheetBehavior = BottomSheetBehavior.from(linerLayout); 453 | 454 | LinearLayoutManager manager = new LinearLayoutManager(this); 455 | recyclerView.setItemAnimator(new DefaultItemAnimator()); 456 | recyclerView.setLayoutManager(manager); 457 | MyAdapter adapter = new MyAdapter(); 458 | recyclerView.setAdapter(adapter); 459 | 460 | // sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);//半打开 461 | sheetBehavior.setHideable(true); 462 | // 463 | sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { 464 | @Override 465 | public void onStateChanged(@NonNull View bottomSheet, int newState) { 466 | if (newState == BottomSheetBehavior.STATE_HIDDEN) { 467 | sheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); 468 | 469 | } 470 | } 471 | 472 | @Override 473 | public void onSlide(@NonNull View bottomSheet, float slideOffset) { 474 | 475 | } 476 | }); 477 | } 478 | 479 | 480 | //定位 481 | private void initLocation() { 482 | 483 | mLocationClient = new LocationClient(getApplicationContext()); 484 | myLocationListener = new MyLoacationListener(); 485 | mLocationClient.registerLocationListener(myLocationListener); 486 | 487 | LocationClientOption options = new LocationClientOption(); 488 | options.setCoorType("bd09ll");//坐标类型 489 | options.setIsNeedAddress(true); 490 | options.setOpenGps(true); 491 | options.setScanSpan(1000); 492 | 493 | mLocationClient.setLocOption(options); 494 | 495 | //模式 496 | mLocationMode = MyLocationConfiguration.LocationMode.NORMAL; 497 | 498 | mLoacationBitmap = BitmapDescriptorFactory.fromResource(R.mipmap.navi_map_gps_locked); 499 | 500 | myOrentationListener = new MyOrentationListener(getApplicationContext()); 501 | myOrentationListener.setmListener(new MyOrentationListener.OnOrientationListner() { 502 | @Override 503 | public void onOrientationChanged(float x) { 504 | mCurrentX = x; 505 | } 506 | }); 507 | 508 | } 509 | 510 | 511 | @Override 512 | public boolean onCreateOptionsMenu(Menu menu) { 513 | getMenuInflater().inflate(R.menu.activity_menu, menu); 514 | return super.onCreateOptionsMenu(menu); 515 | } 516 | 517 | @Override 518 | public boolean onOptionsItemSelected(MenuItem item) { 519 | switch (item.getItemId()) { 520 | case R.id.item_1: //普通地图 521 | mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); 522 | break; 523 | case R.id.item_2://卫星地图 524 | mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); 525 | break; 526 | case R.id.item_3: 527 | if (mBaiduMap.isTrafficEnabled()) { 528 | mBaiduMap.setTrafficEnabled(false); 529 | item.setTitle("实时交通ON"); 530 | } else { 531 | mBaiduMap.setTrafficEnabled(true); 532 | item.setTitle("实时交通OFF"); 533 | } 534 | break; 535 | case R.id.item_4: 536 | mLocationMode = MyLocationConfiguration.LocationMode.NORMAL; 537 | break; 538 | case R.id.item_5://跟随模式 539 | mLocationMode = MyLocationConfiguration.LocationMode.FOLLOWING; 540 | break; 541 | case R.id.item_6://罗盘模式 542 | mLocationMode = MyLocationConfiguration.LocationMode.COMPASS; 543 | break; 544 | case R.id.item_7: 545 | addOverLays(MapCar.infos); 546 | break; 547 | case R.id.item_8: 548 | Toast.makeText(this, currentLatLng.latitude + "\n" + currentLatLng.longitude, Toast.LENGTH_SHORT).show(); 549 | break; 550 | } 551 | return super.onOptionsItemSelected(item); 552 | } 553 | 554 | private void addOverLays(List infos) { 555 | //首先清楚定位的浮层 556 | mBaiduMap.clear(); 557 | LatLng latLng = null; 558 | Marker marker = null; 559 | OverlayOptions options; 560 | for (MapCar car : infos) { 561 | //经纬度 562 | latLng = new LatLng(car.getLatitude(), car.getLongitude()); 563 | //图标 564 | options = new MarkerOptions().position(latLng).icon(mMarker).zIndex(5); 565 | marker = (Marker) mBaiduMap.addOverlay(options); 566 | Bundle bundle = new Bundle(); 567 | bundle.putParcelable("car", car); 568 | marker.setExtraInfo(bundle); 569 | } 570 | 571 | //定位到覆盖物的位置,应该是最后一个覆盖物的位置,如果不想定位到覆盖物的位置而是定位到人的位置,注释掉 572 | // MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng); 573 | // mBaiduMap.setMapStatus(msu); 574 | } 575 | 576 | @OnClick({R.id.dh, R.id.mn, R.id.list}) 577 | public void onClick(View view) { 578 | switch (view.getId()) { 579 | case R.id.dh: 580 | routeplanToNavi(currentLatLng, true); 581 | break; 582 | case R.id.mn: 583 | routeplanToNavi(currentLatLng, false); 584 | break; 585 | case R.id.list: 586 | mPresenter.doLoad(0, 1000, mLongitude + "," + mLatitude); 587 | break; 588 | default: 589 | break; 590 | } 591 | 592 | } 593 | 594 | //覆盖物的点击事件 595 | @Override 596 | public boolean onMarkerClick(Marker marker) { 597 | Bundle bundle = marker.getExtraInfo(); 598 | MapCar car = (MapCar) bundle.getParcelable("car"); 599 | 600 | TextView infoText = new TextView(getApplicationContext()); 601 | infoText.setBackgroundResource(R.mipmap.location_tips); 602 | infoText.setPadding(30, 20, 30, 30); 603 | infoText.setText(car.getName()); 604 | infoText.setTextColor(Color.parseColor("#FFFFFF")); 605 | 606 | mBitmapWindow = BitmapDescriptorFactory.fromView(infoText); 607 | final LatLng lng = marker.getPosition(); 608 | Point p = mBaiduMap.getProjection().toScreenLocation(lng); 609 | p.y -= 47; 610 | currentLatLng = mBaiduMap.getProjection().fromScreenLocation(p); 611 | 612 | infoWindow = new InfoWindow(mBitmapWindow, currentLatLng, 0, new InfoWindow.OnInfoWindowClickListener() { 613 | @Override 614 | public void onInfoWindowClick() { 615 | mBaiduMap.hideInfoWindow(); 616 | stopAnimation(); 617 | } 618 | }); 619 | mBaiduMap.showInfoWindow(infoWindow); 620 | startAnimation(); 621 | return true; 622 | } 623 | 624 | private void startAnimation() { 625 | if (dh.getVisibility() == View.VISIBLE || mn.getVisibility() == View.VISIBLE) 626 | return; 627 | dh.startAnimation(shwoAction); 628 | mn.startAnimation(shwoAction); 629 | dh.setVisibility(View.VISIBLE); 630 | mn.setVisibility(View.VISIBLE); 631 | } 632 | 633 | private void stopAnimation() { 634 | if (dh.getVisibility() == View.GONE || mn.getVisibility() == View.GONE) 635 | return; 636 | dh.startAnimation(hideAction); 637 | mn.startAnimation(hideAction); 638 | dh.setVisibility(View.GONE); 639 | mn.setVisibility(View.GONE); 640 | } 641 | 642 | @Override 643 | public void onMapClick(LatLng latLng) { 644 | mBaiduMap.hideInfoWindow(); 645 | stopAnimation(); 646 | } 647 | 648 | @Override 649 | public boolean onMapPoiClick(MapPoi mapPoi) { 650 | return false; 651 | } 652 | 653 | 654 | /** 655 | * 手势操作地图 656 | * 657 | * @param mapStatus 658 | */ 659 | @Override 660 | public void onMapStatusChangeStart(MapStatus mapStatus) { 661 | 662 | } 663 | 664 | /** 665 | * 地图变化中 666 | * 667 | * @param mapStatus 668 | */ 669 | @Override 670 | public void onMapStatusChange(MapStatus mapStatus) { 671 | mBaiduMap.hideInfoWindow(); 672 | stopAnimation(); 673 | } 674 | 675 | /** 676 | * 地图状态改变 677 | * 678 | * @param mapStatus 679 | */ 680 | @Override 681 | public void onMapStatusChangeFinish(MapStatus mapStatus) { 682 | 683 | } 684 | 685 | 686 | private class MyLoacationListener implements BDLocationListener { 687 | @Override 688 | public void onReceiveLocation(BDLocation bdLocation) { 689 | MyLocationData data = new MyLocationData.Builder() 690 | .direction(mCurrentX)//方向 691 | .accuracy(bdLocation.getRadius()) 692 | .latitude(bdLocation.getLatitude()) 693 | .longitude(bdLocation.getLongitude()) 694 | .build(); 695 | 696 | mBaiduMap.setMyLocationData(data); 697 | 698 | //得到经纬度 699 | mLatitude = bdLocation.getLatitude(); 700 | mLongitude = bdLocation.getLongitude(); 701 | 702 | zoom.setLocation(mLatitude, mLongitude); 703 | 704 | /** 705 | * NORMAL:不会实时更新位置 706 | * COMPASS:实时更新位置,罗盘 707 | * FOLLOWING:跟随模式 708 | */ 709 | MyLocationConfiguration config = new MyLocationConfiguration(mLocationMode, true, mLoacationBitmap); 710 | mBaiduMap.setMyLocationConfigeration(config); 711 | // mBaiduMap.setMyLocationEnabled(true);//当不需要定位图层时关闭定位图层 712 | 713 | if (isFirstIn) { 714 | LatLng latLbg = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());//经纬度 715 | MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLbg); 716 | mBaiduMap.animateMapStatus(msu); 717 | isFirstIn = false; 718 | 719 | Toast.makeText(MainActivity.this, bdLocation.getAddrStr(), Toast.LENGTH_SHORT).show(); 720 | } 721 | 722 | } 723 | 724 | @Override 725 | public void onConnectHotSpotMessage(String s, int i) { 726 | 727 | } 728 | } 729 | 730 | /** 731 | * mvp返回结果 732 | * 733 | * @param code 734 | * @param total 735 | * @param page 736 | * @param list 737 | */ 738 | @Override 739 | public void onResult(int code, int total, int page, List list) { 740 | mDialog.setAdd(list); 741 | View parent = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0); 742 | mDialog.showAtLocation(parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); 743 | } 744 | 745 | 746 | @Override 747 | public void onWindowFocusChanged(boolean hasFocus) { 748 | super.onWindowFocusChanged(hasFocus); 749 | if (hasFocus && Build.VERSION.SDK_INT > 19) { 750 | getWindow().getDecorView() 751 | .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE 752 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 753 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 754 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 755 | | View.SYSTEM_UI_FLAG_FULLSCREEN 756 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); 757 | } 758 | } 759 | 760 | @Override 761 | protected void onDestroy() { 762 | super.onDestroy(); 763 | mMapView.onDestroy(); 764 | } 765 | 766 | @Override 767 | protected void onStart() { 768 | super.onStart(); 769 | //开启定位 770 | mBaiduMap.setMyLocationEnabled(true); 771 | if (!mLocationClient.isStarted()) 772 | mLocationClient.start(); 773 | //开启方向传感器 774 | myOrentationListener.start(); 775 | } 776 | 777 | @Override 778 | protected void onPause() { 779 | super.onPause(); 780 | mMapView.onPause(); 781 | } 782 | 783 | @Override 784 | protected void onResume() { 785 | super.onStop(); 786 | mMapView.onResume(); 787 | } 788 | 789 | @Override 790 | protected void onStop() { 791 | super.onStop(); 792 | //结束定位 793 | mBaiduMap.setMyLocationEnabled(false); 794 | mLocationClient.stop(); 795 | //关闭方向传感器 796 | myOrentationListener.stop(); 797 | } 798 | 799 | 800 | @Override 801 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 802 | // TODO Auto-generated method stub 803 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 804 | if (requestCode == authBaseRequestCode) { 805 | for (int ret : grantResults) { 806 | if (ret == 0) { 807 | continue; 808 | } else { 809 | Toast.makeText(MainActivity.this, "缺少导航基本的权限!", Toast.LENGTH_SHORT).show(); 810 | return; 811 | } 812 | } 813 | initNavigatin(); 814 | } else if (requestCode == authComRequestCode) { 815 | for (int ret : grantResults) { 816 | if (ret == 0) { 817 | continue; 818 | } 819 | } 820 | routeplanToNavi(currentLatLng, true); 821 | } 822 | 823 | } 824 | } 825 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/MainActivity__.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.content.Intent; 6 | import android.content.pm.PackageManager; 7 | import android.graphics.Color; 8 | import android.graphics.Point; 9 | import android.os.Build; 10 | import android.os.Bundle; 11 | import android.os.Environment; 12 | import android.os.Handler; 13 | import android.os.Message; 14 | import android.support.design.widget.FloatingActionButton; 15 | import android.support.v7.app.AppCompatActivity; 16 | import android.util.Log; 17 | import android.view.Menu; 18 | import android.view.MenuItem; 19 | import android.view.View; 20 | import android.view.Window; 21 | import android.view.animation.Animation; 22 | import android.view.animation.TranslateAnimation; 23 | import android.widget.ImageView; 24 | import android.widget.TextView; 25 | import android.widget.Toast; 26 | import android.widget.ZoomControls; 27 | 28 | import com.baidu.location.BDLocation; 29 | import com.baidu.location.BDLocationListener; 30 | import com.baidu.location.LocationClient; 31 | import com.baidu.location.LocationClientOption; 32 | import com.baidu.mapapi.SDKInitializer; 33 | import com.baidu.mapapi.map.BaiduMap; 34 | import com.baidu.mapapi.map.BitmapDescriptor; 35 | import com.baidu.mapapi.map.BitmapDescriptorFactory; 36 | import com.baidu.mapapi.map.InfoWindow; 37 | import com.baidu.mapapi.map.MapPoi; 38 | import com.baidu.mapapi.map.MapStatus; 39 | import com.baidu.mapapi.map.MapStatusUpdate; 40 | import com.baidu.mapapi.map.MapStatusUpdateFactory; 41 | import com.baidu.mapapi.map.MapView; 42 | import com.baidu.mapapi.map.Marker; 43 | import com.baidu.mapapi.map.MarkerOptions; 44 | import com.baidu.mapapi.map.MyLocationConfiguration; 45 | import com.baidu.mapapi.map.MyLocationData; 46 | import com.baidu.mapapi.map.OverlayOptions; 47 | import com.baidu.mapapi.model.LatLng; 48 | import com.baidu.navisdk.adapter.BNCommonSettingParam; 49 | import com.baidu.navisdk.adapter.BNRoutePlanNode; 50 | import com.baidu.navisdk.adapter.BNaviSettingManager; 51 | import com.baidu.navisdk.adapter.BaiduNaviManager; 52 | 53 | import java.io.File; 54 | import java.util.ArrayList; 55 | import java.util.LinkedList; 56 | import java.util.List; 57 | 58 | import butterknife.BindView; 59 | import butterknife.ButterKnife; 60 | import butterknife.OnClick; 61 | 62 | public class MainActivity__ extends AppCompatActivity implements BaiduMap.OnMarkerClickListener, BaiduMap.OnMapClickListener, BaiduMap.OnMapStatusChangeListener { 63 | 64 | @BindView(R.id.mMapView) 65 | MapView mMapView; 66 | @BindView(R.id.fab) 67 | FloatingActionButton fab; 68 | 69 | private static final String TAG = "MainActivity"; 70 | @BindView(R.id.dh) 71 | FloatingActionButton dh; 72 | @BindView(R.id.mn) 73 | FloatingActionButton mn; 74 | 75 | private BaiduMap mBaiduMap; 76 | private LocationClient mLocationClient; 77 | private MyLoacationListener myLocationListener; 78 | private boolean isFirstIn = true; 79 | 80 | private double mLatitude; 81 | private double mLongitude; 82 | private BitmapDescriptor mLoacationBitmap; 83 | 84 | private MyOrentationListener myOrentationListener; 85 | private float mCurrentX;//当前位置 86 | 87 | private MyLocationConfiguration.LocationMode mLocationMode; 88 | 89 | //覆盖物 90 | private BitmapDescriptor mMarker; 91 | 92 | //infowindow 93 | private BitmapDescriptor mBitmapWindow; 94 | private InfoWindow infoWindow; 95 | 96 | //显示的动画 97 | private TranslateAnimation shwoAction; 98 | //隐藏时的动画 99 | private TranslateAnimation hideAction; 100 | 101 | //当前选择的经纬度 102 | private LatLng currentLatLng = null; 103 | 104 | //相关权限 105 | private static final String[] authBaseArr = {Manifest.permission.WRITE_EXTERNAL_STORAGE, 106 | Manifest.permission.ACCESS_FINE_LOCATION}; 107 | private static final String[] authComArr = {Manifest.permission.READ_PHONE_STATE}; 108 | private static final int authBaseRequestCode = 1; 109 | private static final int authComRequestCode = 2; 110 | private String APP_FOLDER_NAME = "TMap"; 111 | private String mSDCardPath = null; 112 | public static final String ROUTE_PLAN_NODE = "routePlanNode"; 113 | public static List activityList = new LinkedList(); 114 | private boolean hasInitSuccess = false;//百度导航是否初始化成功 115 | private boolean hasRequestComAuth = false; 116 | 117 | @Override 118 | protected void onCreate(Bundle savedInstanceState) { 119 | super.onCreate(savedInstanceState); 120 | requestWindowFeature(Window.FEATURE_NO_TITLE); 121 | SDKInitializer.initialize(getApplicationContext()); 122 | setContentView(R.layout.activity_main); 123 | ButterKnife.bind(this); 124 | initView(); 125 | initMarker(); 126 | initLocation(); 127 | 128 | 129 | if (initDirs()) { 130 | initNavigatin(); 131 | } 132 | 133 | } 134 | 135 | String authinfo = null; 136 | 137 | /*************************************** 138 | * 导航部分 139 | ***************************************************/ 140 | private void initNavigatin() { 141 | //申请权限 142 | if (Build.VERSION.SDK_INT >= 23) { 143 | if (!hasBasePhoneAuth()) { 144 | this.requestPermissions(authBaseArr, authBaseRequestCode); 145 | return; 146 | } 147 | } 148 | //初始化导航 149 | BaiduNaviManager.getInstance().init(this, mSDCardPath, APP_FOLDER_NAME, new BaiduNaviManager.NaviInitListener() { 150 | @Override 151 | public void onAuthResult(int status, String msg) { 152 | if (0 == status) { 153 | authinfo = "key校验成功!"; 154 | } else { 155 | authinfo = "key校验失败, " + msg; 156 | } 157 | MainActivity__.this.runOnUiThread(new Runnable() { 158 | 159 | @Override 160 | public void run() { 161 | Toast.makeText(MainActivity__.this, authinfo, Toast.LENGTH_LONG).show(); 162 | } 163 | }); 164 | } 165 | 166 | @Override 167 | public void initStart() { 168 | Toast.makeText(MainActivity__.this, "百度导航初始化开始", Toast.LENGTH_SHORT).show(); 169 | } 170 | 171 | @Override 172 | public void initSuccess() { 173 | Toast.makeText(MainActivity__.this, "百度导航初始化成功", Toast.LENGTH_SHORT).show(); 174 | hasInitSuccess = true; 175 | initSetting(); 176 | } 177 | 178 | @Override 179 | public void initFailed() { 180 | Toast.makeText(MainActivity__.this, "百度导航引擎初始化失败", Toast.LENGTH_SHORT).show(); 181 | } 182 | }, null, ttsHandler, ttsPlayStateListener); 183 | } 184 | 185 | 186 | /** 187 | * 内部TTS播报状态回传handler 188 | */ 189 | private Handler ttsHandler = new Handler() { 190 | public void handleMessage(Message msg) { 191 | int type = msg.what; 192 | switch (type) { 193 | case BaiduNaviManager.TTSPlayMsgType.PLAY_START_MSG: { 194 | Log.d(TAG, "Handler : TTS play start"); 195 | break; 196 | } 197 | case BaiduNaviManager.TTSPlayMsgType.PLAY_END_MSG: { 198 | Log.d(TAG, "Handler : TTS play end"); 199 | break; 200 | } 201 | default: 202 | showToastMsg("TTS验证失败"); 203 | Log.d(TAG, "TTS验证失败"); 204 | break; 205 | } 206 | } 207 | }; 208 | 209 | private void initSetting() { 210 | // BNaviSettingManager.setDayNightMode(BNaviSettingManager.DayNightMode.DAY_NIGHT_MODE_DAY); 211 | BNaviSettingManager 212 | .setShowTotalRoadConditionBar(BNaviSettingManager.PreViewRoadCondition.ROAD_CONDITION_BAR_SHOW_ON); 213 | BNaviSettingManager.setVoiceMode(BNaviSettingManager.VoiceMode.Veteran); 214 | // BNaviSettingManager.setPowerSaveMode(BNaviSettingManager.PowerSaveMode.DISABLE_MODE); 215 | BNaviSettingManager.setRealRoadCondition(BNaviSettingManager.RealRoadCondition.NAVI_ITS_ON); 216 | Bundle bundle = new Bundle(); 217 | // 必须设置APPID,否则会静音 218 | bundle.putString(BNCommonSettingParam.TTS_APP_ID, "0F5B74755E163F0570459A939D1DF18E"); 219 | Log.d(TAG, "设置APPID"); 220 | BNaviSettingManager.setNaviSdkParam(bundle); 221 | } 222 | 223 | /** 224 | * 内部TTS播报状态回调接口 225 | */ 226 | private BaiduNaviManager.TTSPlayStateListener ttsPlayStateListener = new BaiduNaviManager.TTSPlayStateListener() { 227 | 228 | @Override 229 | public void playEnd() { 230 | Log.d(TAG, "TTSPlayStateListener : TTS play end"); 231 | } 232 | 233 | @Override 234 | public void playStart() { 235 | Log.d(TAG, "TTSPlayStateListener : TTS play start"); 236 | } 237 | }; 238 | 239 | public void showToastMsg(final String msg) { 240 | MainActivity__.this.runOnUiThread(new Runnable() { 241 | 242 | @Override 243 | public void run() { 244 | Toast.makeText(MainActivity__.this, msg, Toast.LENGTH_SHORT).show(); 245 | } 246 | }); 247 | } 248 | 249 | //初始化文件路径 250 | private boolean initDirs() { 251 | mSDCardPath = getSdcardDir(); 252 | if (mSDCardPath == null) { 253 | return false; 254 | } 255 | File f = new File(mSDCardPath, APP_FOLDER_NAME); 256 | if (!f.exists()) { 257 | try { 258 | f.mkdir(); 259 | } catch (Exception e) { 260 | e.printStackTrace(); 261 | return false; 262 | } 263 | } 264 | return true; 265 | } 266 | 267 | //判断是否有Sd卡 268 | private String getSdcardDir() { 269 | if (Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) { 270 | return Environment.getExternalStorageDirectory().toString(); 271 | } 272 | return null; 273 | } 274 | 275 | 276 | private boolean hasBasePhoneAuth() { 277 | if (Build.VERSION.SDK_INT >= 23) { 278 | PackageManager pm = this.getPackageManager(); 279 | for (String auth : authComArr) { 280 | if (pm.checkPermission(auth, this.getPackageName()) != PackageManager.PERMISSION_GRANTED) { 281 | return false; 282 | } 283 | } 284 | } 285 | return true; 286 | } 287 | 288 | 289 | private void routeplanToNavi(LatLng currentLatLng, boolean isSimulation) { 290 | BNRoutePlanNode.CoordinateType mCoordinateType = BNRoutePlanNode.CoordinateType.BD09LL; 291 | if (!hasInitSuccess) { 292 | Toast.makeText(MainActivity__.this, "还未初始化!", Toast.LENGTH_SHORT).show(); 293 | } 294 | // 权限申请 295 | if (Build.VERSION.SDK_INT >= 23) { 296 | // 保证导航功能完备 297 | if (!hasCompletePhoneAuth()) { 298 | if (!hasRequestComAuth) { 299 | hasRequestComAuth = true; 300 | this.requestPermissions(authComArr, authComRequestCode); 301 | return; 302 | } else { 303 | Toast.makeText(MainActivity__.this, "没有完备的权限!", Toast.LENGTH_SHORT).show(); 304 | } 305 | } 306 | 307 | } 308 | 309 | BNRoutePlanNode sNode = null; 310 | BNRoutePlanNode eNode = null; 311 | 312 | 313 | // sNode = new BNRoutePlanNode(113.9512500000, 22.5489710000, "出发地", null, mCoordinateType); 314 | // eNode = new BNRoutePlanNode(113.9410840000, 22.5460020000, "终点站", null, mCoordinateType); 315 | 316 | sNode = new BNRoutePlanNode(mLongitude, mLatitude, "起始地", null, mCoordinateType); 317 | eNode = new BNRoutePlanNode(currentLatLng.longitude, currentLatLng.latitude, "目的地", null, mCoordinateType); 318 | 319 | if (sNode != null && eNode != null) { 320 | List list = new ArrayList(); 321 | list.add(sNode); 322 | list.add(eNode); 323 | BaiduNaviManager.getInstance().launchNavigator(this, list, 1, isSimulation, new DemoRoutePlanListener(sNode)); 324 | } 325 | } 326 | 327 | 328 | public class DemoRoutePlanListener implements BaiduNaviManager.RoutePlanListener { 329 | 330 | private BNRoutePlanNode mBNRoutePlanNode = null; 331 | 332 | public DemoRoutePlanListener(BNRoutePlanNode node) { 333 | mBNRoutePlanNode = node; 334 | } 335 | 336 | @Override 337 | public void onJumpToNavigator() { 338 | 339 | //设置途径点以及resetEndNode会回调该接口 340 | 341 | for (Activity ac : activityList) { 342 | if (ac.getClass().getName().endsWith("BNGuideActivity")) { 343 | return; 344 | } 345 | } 346 | Intent intent = new Intent(MainActivity__.this, BNGuideActivity.class); 347 | Bundle bundle = new Bundle(); 348 | bundle.putSerializable(ROUTE_PLAN_NODE, (BNRoutePlanNode) mBNRoutePlanNode); 349 | intent.putExtras(bundle); 350 | startActivity(intent); 351 | 352 | } 353 | 354 | @Override 355 | public void onRoutePlanFailed() { 356 | // TODO Auto-generated method stub 357 | Toast.makeText(MainActivity__.this, "算路失败", Toast.LENGTH_SHORT).show(); 358 | } 359 | } 360 | 361 | 362 | private boolean hasCompletePhoneAuth() { 363 | // TODO Auto-generated method stub 364 | 365 | PackageManager pm = this.getPackageManager(); 366 | for (String auth : authComArr) { 367 | if (pm.checkPermission(auth, this.getPackageName()) != PackageManager.PERMISSION_GRANTED) { 368 | return false; 369 | } 370 | } 371 | return true; 372 | } 373 | 374 | /*****************************************************************************************/ 375 | private void initMarker() { 376 | mMarker = BitmapDescriptorFactory.fromResource(R.mipmap.ic_mb); 377 | addOverLays(MapCar.infos); 378 | } 379 | 380 | private void initView() { 381 | 382 | shwoAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, 383 | Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 384 | 1.0f, Animation.RELATIVE_TO_SELF, 0.0f); 385 | shwoAction.setDuration(300); 386 | 387 | hideAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, 388 | Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 389 | 0.0f, Animation.RELATIVE_TO_SELF, 1.0f); 390 | hideAction.setDuration(300); 391 | 392 | 393 | mBaiduMap = mMapView.getMap(); 394 | //隐藏缩放控件 395 | mMapView.showZoomControls(true); 396 | //是否显示比例尺,默认true 397 | mMapView.showScaleControl(true); 398 | 399 | //隐藏百度logo 400 | View child = mMapView.getChildAt(1); 401 | if (child != null && (child instanceof ImageView || child instanceof ZoomControls)) 402 | child.setVisibility(View.INVISIBLE); 403 | 404 | //覆盖物的点击事件 405 | mBaiduMap.setOnMarkerClickListener(this); 406 | //地图的点击事件 407 | mBaiduMap.setOnMapClickListener(this); 408 | //地图状态事件 409 | mBaiduMap.setOnMapStatusChangeListener(this); 410 | mBaiduMap.setMyLocationEnabled(true);//开启定位图层 411 | MapStatusUpdate status = MapStatusUpdateFactory.zoomTo(15.0F); 412 | mBaiduMap.setMapStatus(status); 413 | 414 | 415 | } 416 | 417 | 418 | //定位 419 | private void initLocation() { 420 | 421 | mLocationClient = new LocationClient(getApplicationContext()); 422 | myLocationListener = new MyLoacationListener(); 423 | mLocationClient.registerLocationListener(myLocationListener); 424 | 425 | LocationClientOption options = new LocationClientOption(); 426 | options.setCoorType("bd09ll");//坐标类型 427 | options.setIsNeedAddress(true); 428 | options.setOpenGps(true); 429 | options.setScanSpan(1000); 430 | 431 | mLocationClient.setLocOption(options); 432 | 433 | //模式 434 | mLocationMode = MyLocationConfiguration.LocationMode.NORMAL; 435 | 436 | mLoacationBitmap = BitmapDescriptorFactory.fromResource(R.mipmap.navi_map_gps_locked); 437 | 438 | myOrentationListener = new MyOrentationListener(getApplicationContext()); 439 | myOrentationListener.setmListener(new MyOrentationListener.OnOrientationListner() { 440 | @Override 441 | public void onOrientationChanged(float x) { 442 | mCurrentX = x; 443 | } 444 | }); 445 | 446 | } 447 | 448 | 449 | @Override 450 | public boolean onCreateOptionsMenu(Menu menu) { 451 | getMenuInflater().inflate(R.menu.activity_menu, menu); 452 | return super.onCreateOptionsMenu(menu); 453 | } 454 | 455 | @Override 456 | public boolean onOptionsItemSelected(MenuItem item) { 457 | switch (item.getItemId()) { 458 | case R.id.item_1: //普通地图 459 | mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL); 460 | break; 461 | case R.id.item_2://卫星地图 462 | mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE); 463 | break; 464 | case R.id.item_3: 465 | if (mBaiduMap.isTrafficEnabled()) { 466 | mBaiduMap.setTrafficEnabled(false); 467 | item.setTitle("实时交通ON"); 468 | } else { 469 | mBaiduMap.setTrafficEnabled(true); 470 | item.setTitle("实时交通OFF"); 471 | } 472 | break; 473 | case R.id.item_4: 474 | mLocationMode = MyLocationConfiguration.LocationMode.NORMAL; 475 | break; 476 | case R.id.item_5://跟随模式 477 | mLocationMode = MyLocationConfiguration.LocationMode.FOLLOWING; 478 | break; 479 | case R.id.item_6://罗盘模式 480 | mLocationMode = MyLocationConfiguration.LocationMode.COMPASS; 481 | break; 482 | case R.id.item_7: 483 | addOverLays(MapCar.infos); 484 | break; 485 | case R.id.item_8: 486 | Toast.makeText(this, currentLatLng.latitude + "\n" + currentLatLng.longitude, Toast.LENGTH_SHORT).show(); 487 | break; 488 | } 489 | return super.onOptionsItemSelected(item); 490 | } 491 | 492 | private void addOverLays(List infos) { 493 | //首先清楚定位的浮层 494 | mBaiduMap.clear(); 495 | LatLng latLng = null; 496 | Marker marker = null; 497 | OverlayOptions options; 498 | for (MapCar car : infos) { 499 | //经纬度 500 | latLng = new LatLng(car.getLatitude(), car.getLongitude()); 501 | //图标 502 | options = new MarkerOptions().position(latLng).icon(mMarker).zIndex(5); 503 | marker = (Marker) mBaiduMap.addOverlay(options); 504 | Bundle bundle = new Bundle(); 505 | bundle.putParcelable("car", car); 506 | marker.setExtraInfo(bundle); 507 | } 508 | 509 | //定位到覆盖物的位置,应该是最后一个覆盖物的位置,如果不想定位到覆盖物的位置而是定位到人的位置,注释掉 510 | // MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng); 511 | // mBaiduMap.setMapStatus(msu); 512 | } 513 | 514 | @OnClick({R.id.fab, R.id.dh, R.id.mn}) 515 | public void onClick(View view) { 516 | switch (view.getId()) { 517 | case R.id.fab: 518 | LatLng lng = new LatLng(mLatitude, mLongitude); 519 | MapStatusUpdate status = MapStatusUpdateFactory.newLatLng(lng); 520 | mBaiduMap.animateMapStatus(status); 521 | break; 522 | case R.id.dh: 523 | routeplanToNavi(currentLatLng, true); 524 | break; 525 | case R.id.mn: 526 | routeplanToNavi(currentLatLng, false); 527 | break; 528 | } 529 | 530 | } 531 | 532 | //覆盖物的点击事件 533 | @Override 534 | public boolean onMarkerClick(Marker marker) { 535 | Bundle bundle = marker.getExtraInfo(); 536 | MapCar car = (MapCar) bundle.getParcelable("car"); 537 | 538 | TextView infoText = new TextView(getApplicationContext()); 539 | infoText.setBackgroundResource(R.mipmap.location_tips); 540 | infoText.setPadding(30, 20, 30, 30); 541 | infoText.setText(car.getName()); 542 | infoText.setTextColor(Color.parseColor("#FFFFFF")); 543 | 544 | mBitmapWindow = BitmapDescriptorFactory.fromView(infoText); 545 | final LatLng lng = marker.getPosition(); 546 | Point p = mBaiduMap.getProjection().toScreenLocation(lng); 547 | p.y -= 47; 548 | currentLatLng = mBaiduMap.getProjection().fromScreenLocation(p); 549 | 550 | infoWindow = new InfoWindow(mBitmapWindow, currentLatLng, 0, new InfoWindow.OnInfoWindowClickListener() { 551 | @Override 552 | public void onInfoWindowClick() { 553 | mBaiduMap.hideInfoWindow(); 554 | stopAnimation(); 555 | } 556 | }); 557 | mBaiduMap.showInfoWindow(infoWindow); 558 | startAnimation(); 559 | return true; 560 | } 561 | 562 | private void startAnimation() { 563 | if (dh.getVisibility() == View.VISIBLE || mn.getVisibility() == View.VISIBLE) 564 | return; 565 | dh.startAnimation(shwoAction); 566 | mn.startAnimation(shwoAction); 567 | dh.setVisibility(View.VISIBLE); 568 | mn.setVisibility(View.VISIBLE); 569 | } 570 | 571 | private void stopAnimation() { 572 | if (dh.getVisibility() == View.GONE || mn.getVisibility() == View.GONE) 573 | return; 574 | dh.startAnimation(hideAction); 575 | mn.startAnimation(hideAction); 576 | dh.setVisibility(View.GONE); 577 | mn.setVisibility(View.GONE); 578 | } 579 | 580 | @Override 581 | public void onMapClick(LatLng latLng) { 582 | mBaiduMap.hideInfoWindow(); 583 | stopAnimation(); 584 | } 585 | 586 | @Override 587 | public boolean onMapPoiClick(MapPoi mapPoi) { 588 | return false; 589 | } 590 | 591 | 592 | /** 593 | * 手势操作地图 594 | * 595 | * @param mapStatus 596 | */ 597 | @Override 598 | public void onMapStatusChangeStart(MapStatus mapStatus) { 599 | 600 | } 601 | 602 | /** 603 | * 地图变化中 604 | * 605 | * @param mapStatus 606 | */ 607 | @Override 608 | public void onMapStatusChange(MapStatus mapStatus) { 609 | mBaiduMap.hideInfoWindow(); 610 | stopAnimation(); 611 | } 612 | 613 | /** 614 | * 地图状态改变 615 | * 616 | * @param mapStatus 617 | */ 618 | @Override 619 | public void onMapStatusChangeFinish(MapStatus mapStatus) { 620 | 621 | } 622 | 623 | 624 | private class MyLoacationListener implements BDLocationListener { 625 | @Override 626 | public void onReceiveLocation(BDLocation bdLocation) { 627 | MyLocationData data = new MyLocationData.Builder() 628 | .direction(mCurrentX)//方向 629 | .accuracy(bdLocation.getRadius()) 630 | .latitude(bdLocation.getLatitude()) 631 | .longitude(bdLocation.getLongitude()) 632 | .build(); 633 | 634 | mBaiduMap.setMyLocationData(data); 635 | 636 | //得到经纬度 637 | mLatitude = bdLocation.getLatitude(); 638 | mLongitude = bdLocation.getLongitude(); 639 | 640 | /** 641 | * NORMAL:不会实时更新位置 642 | * COMPASS:实时更新位置,罗盘 643 | * FOLLOWING:跟随模式 644 | */ 645 | MyLocationConfiguration config = new MyLocationConfiguration(mLocationMode, true, mLoacationBitmap); 646 | mBaiduMap.setMyLocationConfigeration(config); 647 | // mBaiduMap.setMyLocationEnabled(true);//当不需要定位图层时关闭定位图层 648 | 649 | if (isFirstIn) { 650 | LatLng latLbg = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude());//经纬度 651 | MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLbg); 652 | mBaiduMap.animateMapStatus(msu); 653 | isFirstIn = false; 654 | 655 | Toast.makeText(MainActivity__.this, bdLocation.getAddrStr(), Toast.LENGTH_SHORT).show(); 656 | } 657 | 658 | } 659 | 660 | @Override 661 | public void onConnectHotSpotMessage(String s, int i) { 662 | 663 | } 664 | } 665 | 666 | @Override 667 | public void onWindowFocusChanged(boolean hasFocus) { 668 | super.onWindowFocusChanged(hasFocus); 669 | if (hasFocus && Build.VERSION.SDK_INT > 19) { 670 | getWindow().getDecorView() 671 | .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE 672 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 673 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 674 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 675 | | View.SYSTEM_UI_FLAG_FULLSCREEN 676 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); 677 | } 678 | } 679 | 680 | @Override 681 | protected void onDestroy() { 682 | super.onDestroy(); 683 | mMapView.onDestroy(); 684 | } 685 | 686 | @Override 687 | protected void onStart() { 688 | super.onStart(); 689 | //开启定位 690 | mBaiduMap.setMyLocationEnabled(true); 691 | if (!mLocationClient.isStarted()) 692 | mLocationClient.start(); 693 | //开启方向传感器 694 | myOrentationListener.start(); 695 | } 696 | 697 | @Override 698 | protected void onPause() { 699 | super.onPause(); 700 | mMapView.onPause(); 701 | } 702 | 703 | @Override 704 | protected void onResume() { 705 | super.onStop(); 706 | mMapView.onResume(); 707 | } 708 | 709 | @Override 710 | protected void onStop() { 711 | super.onStop(); 712 | //结束定位 713 | mBaiduMap.setMyLocationEnabled(false); 714 | mLocationClient.stop(); 715 | //关闭方向传感器 716 | myOrentationListener.stop(); 717 | } 718 | 719 | 720 | @Override 721 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 722 | // TODO Auto-generated method stub 723 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 724 | if (requestCode == authBaseRequestCode) { 725 | for (int ret : grantResults) { 726 | if (ret == 0) { 727 | continue; 728 | } else { 729 | Toast.makeText(MainActivity__.this, "缺少导航基本的权限!", Toast.LENGTH_SHORT).show(); 730 | return; 731 | } 732 | } 733 | initNavigatin(); 734 | } else if (requestCode == authComRequestCode) { 735 | for (int ret : grantResults) { 736 | if (ret == 0) { 737 | continue; 738 | } 739 | } 740 | routeplanToNavi(currentLatLng, true); 741 | } 742 | 743 | } 744 | } 745 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/MapCar.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 作者:Tangren_ on 2017/3/29 12:53. 11 | * 邮箱:wu_tangren@163.com 12 | * TODO:一句话描述 13 | */ 14 | 15 | public class MapCar implements Parcelable { 16 | private double latitude; 17 | private double longitude; 18 | private int imgId; 19 | private String name; 20 | 21 | static List infos = new ArrayList(); 22 | 23 | static { 24 | infos.add(new MapCar(22.5489710000, 113.9512500000, R.mipmap.ic_mb, "摩拜单车001")); 25 | infos.add(new MapCar(22.5460020000, 113.9410840000, R.mipmap.ic_mb, "摩拜单车002")); 26 | infos.add(new MapCar(22.5489510000, 113.9500220000, R.mipmap.ic_mb, "摩拜单车003")); 27 | infos.add(new MapCar(22.5493970000, 113.9504940000, R.mipmap.ic_mb, "摩拜单车004")); 28 | infos.add(new MapCar(22.5495730000, 113.9506060000, R.mipmap.ic_mb, "摩拜单车005")); 29 | infos.add(new MapCar(22.5496980000, 113.9502240000, R.mipmap.ic_mb, "摩拜单车006")); 30 | 31 | infos.add(new MapCar(22.5498730000,113.9497210000, R.mipmap.ic_mb, "摩拜单车007")); 32 | infos.add(new MapCar(22.5499650000,113.9485980000, R.mipmap.ic_mb, "摩拜单车008")); 33 | infos.add(new MapCar(22.5493560000,113.9499140000, R.mipmap.ic_mb, "摩拜单车009")); 34 | infos.add(new MapCar(22.5489590000,113.9514730000, R.mipmap.ic_mb, "摩拜单车0010")); 35 | infos.add(new MapCar(22.5486630000,113.9515450000, R.mipmap.ic_mb, "摩拜单车0011")); 36 | 37 | infos.add(new MapCar(22.5849200000,113.8857650000, R.mipmap.ic_mb, "摩拜单车0012")); 38 | infos.add(new MapCar(22.5835690000,113.8842200000, R.mipmap.ic_mb, "摩拜单车0013")); 39 | infos.add(new MapCar(22.5821450000,113.8861960000, R.mipmap.ic_mb, "摩拜单车0014")); 40 | infos.add(new MapCar(22.5817900000,113.8844630000, R.mipmap.ic_mb, "摩拜单车0015")); 41 | infos.add(new MapCar(22.5813580000,113.8839190000, R.mipmap.ic_mb, "摩拜单车0016")); 42 | 43 | infos.add(new MapCar(22.5810410000,113.8845160000, R.mipmap.ic_mb, "摩拜单车0017")); 44 | infos.add(new MapCar(22.5811000000,113.8851590000, R.mipmap.ic_mb, "摩拜单车0018")); 45 | infos.add(new MapCar(22.5807200000,113.8848890000, R.mipmap.ic_mb, "摩拜单车0019")); 46 | infos.add(new MapCar(22.5804360000,113.8845120000, R.mipmap.ic_mb, "摩拜单车0020")); 47 | infos.add(new MapCar(22.5803910000,113.8841260000, R.mipmap.ic_mb, "摩拜单车0021")); 48 | 49 | infos.add(new MapCar(22.5803650000,113.8820280000, R.mipmap.ic_mb, "摩拜单车0022")); 50 | infos.add(new MapCar(22.5796480000,113.8830430000, R.mipmap.ic_mb, "摩拜单车0023")); 51 | infos.add(new MapCar(22.5817590000,113.8852890000, R.mipmap.ic_mb, "摩拜单车0024")); 52 | infos.add(new MapCar(22.5832080000,113.8902880000, R.mipmap.ic_mb, "摩拜单车0025")); 53 | infos.add(new MapCar(22.5839090000,113.8899110000, R.mipmap.ic_mb, "摩拜单车0026")); 54 | } 55 | 56 | public MapCar(double latitude, double longitude, int imgId, String name) { 57 | this.latitude = latitude; 58 | this.longitude = longitude; 59 | this.imgId = imgId; 60 | this.name = name; 61 | } 62 | 63 | public double getLatitude() { 64 | return latitude; 65 | } 66 | 67 | public MapCar setLatitude(double latitude) { 68 | this.latitude = latitude; 69 | return this; 70 | } 71 | 72 | public double getLongitude() { 73 | return longitude; 74 | } 75 | 76 | public MapCar setLongitude(double longitude) { 77 | this.longitude = longitude; 78 | return this; 79 | } 80 | 81 | public int getImgId() { 82 | return imgId; 83 | } 84 | 85 | public MapCar setImgId(int imgId) { 86 | this.imgId = imgId; 87 | return this; 88 | } 89 | 90 | public String getName() { 91 | return name; 92 | } 93 | 94 | public MapCar setName(String name) { 95 | this.name = name; 96 | return this; 97 | } 98 | 99 | @Override 100 | public int describeContents() { 101 | return 0; 102 | } 103 | 104 | @Override 105 | public void writeToParcel(Parcel dest, int flags) { 106 | dest.writeDouble(this.latitude); 107 | dest.writeDouble(this.longitude); 108 | dest.writeInt(this.imgId); 109 | dest.writeString(this.name); 110 | } 111 | 112 | public MapCar() { 113 | } 114 | 115 | protected MapCar(Parcel in) { 116 | this.latitude = in.readDouble(); 117 | this.longitude = in.readDouble(); 118 | this.imgId = in.readInt(); 119 | this.name = in.readString(); 120 | } 121 | 122 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 123 | @Override 124 | public MapCar createFromParcel(Parcel source) { 125 | return new MapCar(source); 126 | } 127 | 128 | @Override 129 | public MapCar[] newArray(int size) { 130 | return new MapCar[size]; 131 | } 132 | }; 133 | 134 | @Override 135 | public String toString() { 136 | return "MapCar{" + 137 | "latitude=" + latitude + 138 | ", longitude=" + longitude + 139 | ", name='" + name + '\'' + 140 | '}'; 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map; 2 | 3 | import android.app.Application; 4 | 5 | import com.yanzhenjie.nohttp.Logger; 6 | import com.yanzhenjie.nohttp.NoHttp; 7 | import com.yanzhenjie.nohttp.OkHttpNetworkExecutor; 8 | 9 | /** 10 | * 作者:Tangren_ on 2017/3/31 16:00. 11 | * 邮箱:wu_tangren@163.com 12 | * TODO:一句话描述 13 | */ 14 | 15 | public class MyApplication extends Application { 16 | 17 | private static MyApplication instance; 18 | 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | instance = this; 23 | NoHttp.initialize(this, new NoHttp.Config() 24 | .setNetworkExecutor(new OkHttpNetworkExecutor())); 25 | Logger.setDebug(true); 26 | Logger.setTag("----Debug日志:----"); 27 | 28 | } 29 | 30 | public static MyApplication getInstance() { 31 | if (instance == null) { 32 | synchronized (MyApplication.class) { 33 | if (instance == null) 34 | instance = new MyApplication(); 35 | } 36 | } 37 | return instance; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/MyOrentationListener.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map; 2 | 3 | import android.content.Context; 4 | import android.hardware.Sensor; 5 | import android.hardware.SensorEvent; 6 | import android.hardware.SensorEventListener; 7 | import android.hardware.SensorManager; 8 | 9 | /** 10 | * 作者:Tangren_ on 2017/3/29 10:57. 11 | * 邮箱:wu_tangren@163.com 12 | * TODO:方向传感器 13 | */ 14 | 15 | public class MyOrentationListener implements SensorEventListener { 16 | 17 | private SensorManager mSensorManager; 18 | private Context mContext; 19 | private Sensor mSensor; 20 | 21 | private float lastX; 22 | 23 | 24 | public MyOrentationListener(Context mContext) { 25 | this.mContext = mContext; 26 | } 27 | 28 | public void start() { 29 | mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); 30 | if (mSensorManager != null) { 31 | //获得方向传感器 32 | mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); 33 | } 34 | if (mSensor != null) { 35 | mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_UI); 36 | } 37 | } 38 | 39 | public void stop() { 40 | mSensorManager.unregisterListener(this); 41 | } 42 | 43 | 44 | @Override 45 | public void onSensorChanged(SensorEvent event) { 46 | if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) { 47 | float x = event.values[SensorManager.DATA_X]; 48 | if (Math.abs(x - lastX) > 1.0) { 49 | if (mListener != null) { 50 | mListener.onOrientationChanged(x); 51 | } 52 | } 53 | 54 | lastX = x; 55 | } 56 | } 57 | 58 | //精度发生改变 59 | @Override 60 | public void onAccuracyChanged(Sensor sensor, int accuracy) { 61 | 62 | } 63 | 64 | 65 | private OnOrientationListner mListener; 66 | 67 | public MyOrentationListener setmListener(OnOrientationListner mListener) { 68 | this.mListener = mListener; 69 | return this; 70 | } 71 | 72 | public interface OnOrientationListner { 73 | void onOrientationChanged(float x); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/NavigatinActivity.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map; 2 | 3 | import android.os.Bundle; 4 | import android.os.PersistableBundle; 5 | import android.support.design.widget.FloatingActionButton; 6 | import android.support.v7.app.AppCompatActivity; 7 | 8 | import com.baidu.mapapi.map.MapView; 9 | 10 | import butterknife.BindView; 11 | import butterknife.ButterKnife; 12 | import butterknife.OnClick; 13 | 14 | /** 15 | * 作者:Tangren_ on 2017/3/29 18:20. 16 | * 邮箱:wu_tangren@163.com 17 | * TODO:一句话描述 18 | */ 19 | 20 | public class NavigatinActivity extends AppCompatActivity { 21 | @BindView(R.id.mMapView) 22 | MapView mMapView; 23 | @BindView(R.id.fab) 24 | FloatingActionButton fab; 25 | 26 | @Override 27 | public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { 28 | super.onCreate(savedInstanceState, persistentState); 29 | setContentView(R.layout.activity_main); 30 | ButterKnife.bind(this); 31 | 32 | } 33 | 34 | 35 | @OnClick(R.id.fab) 36 | public void onClick() { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/TODO: -------------------------------------------------------------------------------- 1 | 1.jar包+so库的引用 2 | 初始化(在setConView()之前调用,建议在application) 3 | SDKInitializer.initialize(getApplicationContext()); 4 | 5 | MapStatusUpdate status = MapStatusUpdateFactory.zoomTo(15.0F); 6 | mBaiduMap.setMapStatus(status); 7 | 8 | 2.加入定位,集成方向传感器 9 | LocationClient 10 | LocationClientOption定位的一些设置 11 | BDLocationListener 12 | BDLocation 13 | MyLocationData 14 | 自定义图标 15 | BitmapDescriptor 16 | 引入方向传感器 17 | SensorManager-Sensor 18 | BDLocationListener对方向进行设置 19 | 20 | 3.模式切换 21 | mLocationMode:三种模式,NORMAL、FOLLOWING、COMPASS(圆盘,实时定位) 22 | MyLocationConfiguration config = new MyLocationConfiguration(mLocationMode, true, mLoacationBitmap); 23 | mBaiduMap.setMyLocationConfigeration(config); 24 | 25 | 4.添加覆盖物,覆盖物的点击事件以及InfoWindow 26 | Marker:覆盖物标示 27 | OverlayOptions 指定位置坐标 28 | Baidumap.setOnMarerClickListener 29 | InfoWindow:BaiduMap.showInfowindow,BaiduMap.hideInfoWindow 30 | 31 | 32 | 5.事件 33 | //覆盖物的点击事件 34 | mBaiduMap.setOnMarkerClickListener(this); 35 | //地图的点击事件 36 | mBaiduMap.setOnMapClickListener(this); 37 | //地图状态事件 38 | mBaiduMap.setOnMapStatusChangeListener(this); -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/adapter/ListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.wxx.map.R; 10 | import com.wxx.map.bean.ListData; 11 | 12 | import java.util.List; 13 | 14 | import butterknife.BindView; 15 | import butterknife.ButterKnife; 16 | 17 | /** 18 | * 作者:Tangren_ on 2017/4/1 10:25. 19 | * 邮箱:wu_tangren@163.com 20 | * TODO:一句话描述 21 | */ 22 | 23 | public class ListAdapter extends RecyclerView.Adapter { 24 | 25 | private List list; 26 | 27 | @Override 28 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 29 | LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 30 | return new ListHolder(inflater.inflate(R.layout.list_item_view, parent, false)); 31 | } 32 | 33 | @Override 34 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 35 | ListData.ContentsBean bean = list.get(position); 36 | if (bean == null) 37 | return; 38 | ListHolder listHolder = (ListHolder) holder; 39 | listHolder.address.setText(bean.getAddress()); 40 | listHolder.title.setText(bean.getTitle()); 41 | listHolder.distance.setText("距离:" + bean.getDistance() + "米"); 42 | } 43 | 44 | @Override 45 | public int getItemCount() { 46 | return list == null ? 0 : list.size(); 47 | } 48 | 49 | public void loadMore(List list) { 50 | if (list == null) { 51 | add(list); 52 | } else { 53 | this.list.addAll(list); 54 | notifyDataSetChanged(); 55 | } 56 | } 57 | 58 | public void add(List list) { 59 | this.list = list; 60 | notifyDataSetChanged(); 61 | } 62 | 63 | 64 | class ListHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 65 | @BindView(R.id.address) 66 | TextView address; 67 | @BindView(R.id.title) 68 | TextView title; 69 | @BindView(R.id.distance) 70 | TextView distance; 71 | 72 | public ListHolder(View itemView) { 73 | super(itemView); 74 | ButterKnife.bind(this, itemView); 75 | itemView.setOnClickListener(this); 76 | } 77 | 78 | @Override 79 | public void onClick(View v) { 80 | 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/adapter/MyAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.wxx.map.R; 10 | 11 | /** 12 | * 作者:Tangren_ on 2017/3/31 17:17. 13 | * 邮箱:wu_tangren@163.com 14 | * TODO:一句话描述 15 | */ 16 | 17 | public class MyAdapter extends RecyclerView.Adapter { 18 | 19 | 20 | public MyAdapter() { 21 | } 22 | 23 | @Override 24 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 25 | LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 26 | return new MyHolder(inflater.inflate(R.layout.item, parent, false)); 27 | } 28 | 29 | @Override 30 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 31 | MyHolder myHolder = (MyHolder) holder; 32 | ((MyHolder) holder).textView.setText("item" + position); 33 | } 34 | 35 | @Override 36 | public int getItemCount() { 37 | return 20; 38 | } 39 | 40 | class MyHolder extends RecyclerView.ViewHolder { 41 | public TextView textView; 42 | 43 | public MyHolder(View itemView) { 44 | super(itemView); 45 | textView = (TextView) itemView.findViewById(R.id.title); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/bean/ListData.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.bean; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 作者:Tangren_ on 2017/4/1 10:49. 7 | * 邮箱:wu_tangren@163.com 8 | * TODO:一句话描述 9 | */ 10 | 11 | public class ListData { 12 | 13 | /** 14 | * status : 0 15 | * total : 19 16 | * size : 10 17 | * contents : [{"status":0,"uid":2042622617,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490937860,"city":"深圳市","location":[113.947305,22.551528],"address":"广东省深圳市南山区高新中二道10号","title":"深圳软件园-一期","coord_type":3,"direction":"东南","type":0,"distance":323,"weight":0},{"status":0,"uid":2042625867,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490937964,"city":"深圳市","location":[113.951248,22.549033],"address":"广东省深圳市南山区科发路10号","title":"维用科技大厦","coord_type":3,"direction":"西北","type":0,"distance":169,"weight":0},{"status":0,"uid":2042625939,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490937974,"city":"深圳市","location":[113.950412,22.549392],"address":"广东省深圳市南山区科智西路1号","title":"园西工业区","coord_type":3,"direction":"西北","type":0,"distance":82,"weight":0},{"status":0,"uid":2042626014,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490937984,"city":"深圳市","location":[113.950192,22.549296],"address":"广东省深圳市南山区科智西路1号","title":"园西工业区","coord_type":3,"direction":"北","type":0,"distance":84,"weight":0},{"status":0,"uid":2042626092,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490937994,"city":"深圳市","location":[113.950111,22.548746],"address":"广东省深圳市南山区科发路9-1","title":"科苑西小区","coord_type":3,"direction":"北","type":0,"distance":143,"weight":0},{"status":0,"uid":2042626185,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490938006,"city":"深圳市","location":[113.949986,22.548362],"address":"广东省深圳市南山区科发路9-5","title":"科苑居","coord_type":3,"direction":"北","type":0,"distance":185,"weight":0},{"status":0,"uid":2042626244,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490938014,"city":"深圳市","location":[113.950754,22.548278],"address":"广东省深圳市南山区科发路7-19-2","title":"科苑西小区","coord_type":3,"direction":"北","type":0,"distance":209,"weight":0},{"status":0,"uid":2042626289,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490938022,"city":"深圳市","location":[113.950767,22.54802],"address":"广东省深圳市南山区科发路7号","title":"科苑西小区","coord_type":3,"direction":"北","type":0,"distance":236,"weight":0},{"status":0,"uid":2042626462,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490938043,"city":"深圳市","location":[113.951823,22.548065],"address":"广东省深圳市南山区科苑路3号","title":"科苑西小区","coord_type":3,"direction":"西北","type":0,"distance":287,"weight":0},{"status":0,"uid":2042626558,"province":"广东省","geotable_id":165733,"district":"南山区","create_time":1490938055,"city":"深圳市","location":[113.95136,22.548666],"address":"广东省深圳市南山区科发路5-2","title":"科苑西小区","coord_type":3,"direction":"西北","type":0,"distance":205,"weight":0}] 18 | */ 19 | 20 | private int status; 21 | private int total; 22 | private int size; 23 | private List contents; 24 | 25 | public int getStatus() { 26 | return status; 27 | } 28 | 29 | public void setStatus(int status) { 30 | this.status = status; 31 | } 32 | 33 | public int getTotal() { 34 | return total; 35 | } 36 | 37 | public void setTotal(int total) { 38 | this.total = total; 39 | } 40 | 41 | public int getSize() { 42 | return size; 43 | } 44 | 45 | public void setSize(int size) { 46 | this.size = size; 47 | } 48 | 49 | public List getContents() { 50 | return contents; 51 | } 52 | 53 | public void setContents(List contents) { 54 | this.contents = contents; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "ListData{" + 60 | "status=" + status + 61 | ", total=" + total + 62 | ", size=" + size + 63 | ", contents=" + contents + 64 | '}'; 65 | } 66 | 67 | public static class ContentsBean { 68 | /** 69 | * status : 0 70 | * uid : 2042622617 71 | * province : 广东省 72 | * geotable_id : 165733 73 | * district : 南山区 74 | * create_time : 1490937860 75 | * city : 深圳市 76 | * location : [113.947305,22.551528] 77 | * address : 广东省深圳市南山区高新中二道10号 78 | * title : 深圳软件园-一期 79 | * coord_type : 3 80 | * direction : 东南 81 | * type : 0 82 | * distance : 323 83 | * weight : 0 84 | */ 85 | 86 | private int status; 87 | private int uid; 88 | private String province; 89 | private int geotable_id; 90 | private String district; 91 | private int create_time; 92 | private String city; 93 | private String address; 94 | private String title; 95 | private int coord_type; 96 | private String direction; 97 | private int type; 98 | private int distance; 99 | private int weight; 100 | private List location; 101 | 102 | public int getStatus() { 103 | return status; 104 | } 105 | 106 | public void setStatus(int status) { 107 | this.status = status; 108 | } 109 | 110 | public int getUid() { 111 | return uid; 112 | } 113 | 114 | public void setUid(int uid) { 115 | this.uid = uid; 116 | } 117 | 118 | public String getProvince() { 119 | return province; 120 | } 121 | 122 | public void setProvince(String province) { 123 | this.province = province; 124 | } 125 | 126 | public int getGeotable_id() { 127 | return geotable_id; 128 | } 129 | 130 | public void setGeotable_id(int geotable_id) { 131 | this.geotable_id = geotable_id; 132 | } 133 | 134 | public String getDistrict() { 135 | return district; 136 | } 137 | 138 | public void setDistrict(String district) { 139 | this.district = district; 140 | } 141 | 142 | public int getCreate_time() { 143 | return create_time; 144 | } 145 | 146 | public void setCreate_time(int create_time) { 147 | this.create_time = create_time; 148 | } 149 | 150 | public String getCity() { 151 | return city; 152 | } 153 | 154 | public void setCity(String city) { 155 | this.city = city; 156 | } 157 | 158 | public String getAddress() { 159 | return address; 160 | } 161 | 162 | public void setAddress(String address) { 163 | this.address = address; 164 | } 165 | 166 | public String getTitle() { 167 | return title; 168 | } 169 | 170 | public void setTitle(String title) { 171 | this.title = title; 172 | } 173 | 174 | public int getCoord_type() { 175 | return coord_type; 176 | } 177 | 178 | public void setCoord_type(int coord_type) { 179 | this.coord_type = coord_type; 180 | } 181 | 182 | public String getDirection() { 183 | return direction; 184 | } 185 | 186 | public void setDirection(String direction) { 187 | this.direction = direction; 188 | } 189 | 190 | public int getType() { 191 | return type; 192 | } 193 | 194 | public void setType(int type) { 195 | this.type = type; 196 | } 197 | 198 | public int getDistance() { 199 | return distance; 200 | } 201 | 202 | public void setDistance(int distance) { 203 | this.distance = distance; 204 | } 205 | 206 | public int getWeight() { 207 | return weight; 208 | } 209 | 210 | public void setWeight(int weight) { 211 | this.weight = weight; 212 | } 213 | 214 | public List getLocation() { 215 | return location; 216 | } 217 | 218 | public void setLocation(List location) { 219 | this.location = location; 220 | } 221 | 222 | @Override 223 | public String toString() { 224 | return "ContentsBean{" + 225 | "status=" + status + 226 | ", uid=" + uid + 227 | ", province='" + province + '\'' + 228 | ", geotable_id=" + geotable_id + 229 | ", district='" + district + '\'' + 230 | ", create_time=" + create_time + 231 | ", city='" + city + '\'' + 232 | ", address='" + address + '\'' + 233 | ", title='" + title + '\'' + 234 | ", coord_type=" + coord_type + 235 | ", direction='" + direction + '\'' + 236 | ", type=" + type + 237 | ", distance=" + distance + 238 | ", weight=" + weight + 239 | ", location=" + location + 240 | '}'; 241 | } 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/http/CallServer.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.http; 2 | 3 | import com.yanzhenjie.nohttp.NoHttp; 4 | import com.yanzhenjie.nohttp.rest.Request; 5 | import com.yanzhenjie.nohttp.rest.RequestQueue; 6 | 7 | public class CallServer { 8 | 9 | private static CallServer httpclient; 10 | 11 | // 请求队列 12 | private RequestQueue requestQueuequeue; 13 | 14 | private CallServer() { 15 | requestQueuequeue = NoHttp.newRequestQueue(); 16 | } 17 | 18 | public synchronized static CallServer getHttpclient() { 19 | if (httpclient == null) 20 | httpclient = new CallServer(); 21 | return httpclient; 22 | } 23 | 24 | // 添加一个请求到队列 25 | public void add(int what, Request request, 26 | HttpListener callback) { 27 | requestQueuequeue.add(what, request, new HttpResponseListener 28 | (request, callback)); 29 | } 30 | 31 | // 取消队列中所有请求 32 | public void cancelAll() { 33 | requestQueuequeue.cancelAll(); 34 | } 35 | 36 | // 退出App时停止所有请求 37 | public void stopAll() { 38 | requestQueuequeue.stop(); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/http/HttpListener.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.http; 2 | 3 | 4 | import com.yanzhenjie.nohttp.rest.Response; 5 | 6 | public interface HttpListener { 7 | 8 | void success(int what, Response response); 9 | 10 | void fail(int what, Response response); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/http/HttpResponseListener.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.http; 2 | 3 | import android.content.Context; 4 | 5 | import com.yanzhenjie.nohttp.Logger; 6 | import com.yanzhenjie.nohttp.rest.OnResponseListener; 7 | import com.yanzhenjie.nohttp.rest.Request; 8 | import com.yanzhenjie.nohttp.rest.Response; 9 | 10 | 11 | public class HttpResponseListener implements OnResponseListener { 12 | 13 | private Context context; 14 | 15 | private Request request; 16 | 17 | private HttpListener httpListener; 18 | 19 | /** 20 | * @param request 请求对象 21 | * @param callback 回调对象 22 | */ 23 | public HttpResponseListener(final Request request, 24 | HttpListener callback) { 25 | this.request = request; 26 | this.httpListener = callback; 27 | } 28 | 29 | public void onFinish(int arg0) { 30 | Logger.d("完成"); 31 | 32 | } 33 | 34 | public void onStart(int arg0) { 35 | Logger.i("开始"); 36 | } 37 | 38 | // 成功回调 39 | public void onSucceed(int what, Response response) { 40 | int responseCode = response.getHeaders().getResponseCode(); 41 | System.out.println("responseCode:" + responseCode + ""); 42 | if (responseCode > 400 && context != null) { 43 | if (responseCode == 405) { 44 | Logger.d("服务器暂不支持该类型!"); 45 | } 46 | } 47 | 48 | if (httpListener != null) { 49 | httpListener.success(what, response); 50 | } 51 | } 52 | 53 | @Override 54 | public void onFailed(int what, Response response) { 55 | Logger.i("失败"); 56 | if (httpListener != null) 57 | httpListener.fail(what, response); 58 | 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/mvp/LoadCompl.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.mvp; 2 | 3 | import android.util.Log; 4 | 5 | import com.google.gson.Gson; 6 | import com.wxx.map.bean.ListData; 7 | import com.wxx.map.http.CallServer; 8 | import com.wxx.map.http.HttpListener; 9 | import com.wxx.map.utils.API; 10 | import com.yanzhenjie.nohttp.NoHttp; 11 | import com.yanzhenjie.nohttp.RequestMethod; 12 | import com.yanzhenjie.nohttp.rest.Request; 13 | import com.yanzhenjie.nohttp.rest.Response; 14 | 15 | import java.lang.ref.WeakReference; 16 | 17 | /** 18 | * 作者:Tangren_ on 2017/4/1 11:30. 19 | * 邮箱:wu_tangren@163.com 20 | * TODO:一句话描述 21 | */ 22 | 23 | public class LoadCompl implements LoadPresetner { 24 | 25 | private OnLoadResult view; 26 | 27 | private WeakReference mainActivityWeakReference; 28 | 29 | private static final String TAG = "LoadCompl"; 30 | 31 | 32 | public LoadCompl(OnLoadResult view) { 33 | this.view = view; 34 | mainActivityWeakReference = new WeakReference(view); 35 | } 36 | 37 | @Override 38 | public void doLoad(int page, int radius, String location) { 39 | final OnLoadResult view = mainActivityWeakReference.get(); 40 | if (view != null) { 41 | StringBuffer buffer = new StringBuffer(); 42 | buffer.append("ak=FEHzLBQiiGNeR8r0ad8cINBrRbaW4hHM&") 43 | .append("geotable_id=165733&") 44 | .append("location=" + location + "&") 45 | .append("mcode=DF:39:DD:62:A6:59:0A:76:26:F1:77:AC:C8:63:9E:65:6B:DC:BA:FB;com.wxx.map&") 46 | .append("radius=" + radius + "&") 47 | .append("page_index=" + page); 48 | final Request request = NoHttp.createStringRequest(API.URL + buffer.toString(), RequestMethod.GET); 49 | CallServer.getHttpclient().add(0, request, new HttpListener() { 50 | @Override 51 | public void success(int what, Response response) { 52 | if (view != null) { 53 | ListData listData = new Gson().fromJson(response.get(), ListData.class); 54 | Log.d(TAG, listData.toString()); 55 | view.onResult(1, 20, 0, listData.getContents()); 56 | 57 | } 58 | } 59 | 60 | @Override 61 | public void fail(int what, Response response) { 62 | Log.d(TAG, "失败"); 63 | } 64 | }); 65 | } else { 66 | try { 67 | Log.d(TAG, "哇哦--资源已被销毁----"); 68 | } catch (Exception e) { 69 | Log.d(TAG, e.getMessage()); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/mvp/LoadPresetner.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.mvp; 2 | 3 | /** 4 | * 作者:Tangren_ on 2017/4/1 11:30. 5 | * 邮箱:wu_tangren@163.com 6 | * TODO:一句话描述 7 | */ 8 | 9 | public interface LoadPresetner { 10 | void doLoad(int page, int radius, String location); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/mvp/OnLoadResult.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.mvp; 2 | 3 | import com.wxx.map.bean.ListData; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 作者:Tangren_ on 2017/4/1 11:28. 9 | * 邮箱:wu_tangren@163.com 10 | * TODO:一句话描述 11 | */ 12 | 13 | public interface OnLoadResult { 14 | void onResult(int code, int total, int page, List list); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/utils/API.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.utils; 2 | 3 | /** 4 | * 作者:Tangren_ on 2017/4/1 11:25. 5 | * 邮箱:wu_tangren@163.com 6 | * TODO:一句话描述 7 | */ 8 | 9 | public class API { 10 | public static final String URL = "http://api.map.baidu.com/geosearch/v3/nearby?"; 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/widget/ImageTextView.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Rect; 6 | import android.graphics.drawable.Drawable; 7 | import android.util.AttributeSet; 8 | import android.view.Gravity; 9 | import android.widget.TextView; 10 | 11 | /** 12 | * 作者:Tangren_ on 2016/12/17 20:55. 13 | * 邮箱:wu_tangren@163.com 14 | * TODO:一句话描述 15 | */ 16 | 17 | public class ImageTextView extends TextView { 18 | 19 | private Drawable[] drawables; 20 | 21 | public ImageTextView(Context context) { 22 | super(context); 23 | init(); 24 | } 25 | 26 | 27 | public ImageTextView(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | init(); 30 | } 31 | 32 | public ImageTextView(Context context, AttributeSet attrs, int defStyleAttr) { 33 | super(context, attrs, defStyleAttr); 34 | init(); 35 | } 36 | 37 | private void init() { 38 | drawables = getCompoundDrawables(); 39 | } 40 | 41 | 42 | @Override 43 | protected void onDraw(Canvas canvas) { 44 | 45 | if (null != drawables) { 46 | Drawable drawableLeft = drawables[0]; 47 | Drawable drawableTop = drawables[1]; 48 | Drawable drawableRight = drawables[2]; 49 | //文字宽度 50 | float textWidth = getPaint().measureText(getText().toString()); 51 | if (null != drawableLeft) { 52 | setGravity(Gravity.START | Gravity.CENTER_VERTICAL); 53 | float contentWidth = textWidth + getCompoundDrawablePadding() + drawableLeft.getIntrinsicWidth(); 54 | canvas.translate((getWidth() - contentWidth) / 2, 0); 55 | } 56 | if (null != drawableRight) { 57 | setGravity(Gravity.END | Gravity.CENTER_VERTICAL); 58 | float contentWidth = textWidth + getCompoundDrawablePadding() + drawableRight.getIntrinsicWidth(); 59 | canvas.translate(-(getWidth() - contentWidth) / 2, 0); 60 | } 61 | 62 | if (null != drawableTop) { 63 | Rect rect = new Rect(); 64 | getPaint().getTextBounds(getText().toString(), 0, getText().toString().length(), rect); 65 | float textHeight = rect.height(); 66 | int drawablePadding = getCompoundDrawablePadding(); 67 | int drawableHeight = drawableTop.getIntrinsicHeight(); 68 | float bodyHeight = textHeight + drawablePadding + drawableHeight; 69 | canvas.translate(0, (getHeight() - bodyHeight) / 2); 70 | } 71 | } 72 | 73 | super.onDraw(canvas); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/widget/ListDialog.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.graphics.drawable.ColorDrawable; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.util.DisplayMetrics; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.PopupWindow; 14 | import android.widget.TextView; 15 | 16 | import com.wxx.map.R; 17 | import com.wxx.map.adapter.ListAdapter; 18 | import com.wxx.map.bean.ListData; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * 作者:Tangren_ on 2017/3/31 16:02. 24 | * 邮箱:wu_tangren@163.com 25 | * TODO:一句话描述 26 | */ 27 | 28 | public class ListDialog extends PopupWindow { 29 | private TextView dis; 30 | private RecyclerView recyclerView; 31 | private AppCompatActivity mContext; 32 | private View view; 33 | private ListAdapter mAdapter; 34 | 35 | public ListDialog(AppCompatActivity context) { 36 | super(context); 37 | this.mContext = context; 38 | mAdapter = new ListAdapter(); 39 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 40 | view = inflater.inflate(R.layout.popu_view, null); 41 | dis = (TextView) view.findViewById(R.id.dis); 42 | recyclerView = (RecyclerView) view.findViewById(R.id.lRecyclerView); 43 | dis.setOnClickListener(new View.OnClickListener() { 44 | @Override 45 | public void onClick(View v) { 46 | dismiss(); 47 | } 48 | }); 49 | LinearLayoutManager manager = new LinearLayoutManager(context); 50 | recyclerView.setLayoutManager(manager); 51 | 52 | this.setContentView(view); 53 | this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); 54 | this.setHeight(getPopHeight()); 55 | this.setFocusable(false); 56 | this.setAnimationStyle(R.style.animBottom); 57 | this.setOutsideTouchable(false); 58 | ColorDrawable drawable = new ColorDrawable(Color.parseColor("#FFFFFF")); 59 | this.setBackgroundDrawable(drawable); 60 | } 61 | 62 | public void setAdd(List list) { 63 | mAdapter.add(list); 64 | recyclerView.setAdapter(mAdapter); 65 | } 66 | 67 | public void setMore(List list) { 68 | mAdapter.loadMore(list); 69 | } 70 | 71 | private int getPopHeight() { 72 | DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); 73 | return (int) (metrics.heightPixels * 0.6); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/wxx/map/widget/ZoomControView.java: -------------------------------------------------------------------------------- 1 | package com.wxx.map.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.LinearLayout; 9 | 10 | import com.baidu.mapapi.map.BaiduMap; 11 | import com.baidu.mapapi.map.MapStatus; 12 | import com.baidu.mapapi.map.MapStatusUpdate; 13 | import com.baidu.mapapi.map.MapStatusUpdateFactory; 14 | import com.baidu.mapapi.map.MapView; 15 | import com.baidu.mapapi.model.LatLng; 16 | import com.wxx.map.R; 17 | 18 | /** 19 | * 作者:Tangren_ on 2017/3/30 20:06. 20 | * 邮箱:wu_tangren@163.com 21 | * TODO:一句话描述 22 | */ 23 | 24 | public class ZoomControView extends LinearLayout implements View.OnClickListener, BaiduMap.OnMapStatusChangeListener { 25 | 26 | //放大按钮 27 | private Button enlargeBtn; 28 | 29 | //缩小按钮 30 | private Button narrowBtn; 31 | 32 | //路况 33 | private Button roadlingt; 34 | 35 | //定位 36 | private Button location; 37 | 38 | private BaiduMap mBaiduMap; 39 | 40 | //地图状态 41 | private MapStatus mStatus; 42 | 43 | //地图最小缩小 44 | private float minZoomLevel; 45 | 46 | //地图最大放大 47 | private float maxZoomLevel; 48 | 49 | private LinearLayout itemView; 50 | 51 | private double mLatitude; 52 | private double mLongitude; 53 | 54 | public ZoomControView(Context context) { 55 | this(context, null); 56 | } 57 | 58 | public ZoomControView(Context context, AttributeSet attrs) { 59 | this(context, attrs, 0); 60 | } 61 | 62 | public ZoomControView(Context context, AttributeSet attrs, int defStyleAttr) { 63 | super(context, attrs, defStyleAttr); 64 | init(); 65 | } 66 | 67 | private void init() { 68 | 69 | itemView = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.item_zoom, null); 70 | narrowBtn = (Button) itemView.findViewById(R.id.narrowBtn); 71 | enlargeBtn = (Button) itemView.findViewById(R.id.enlargeBtn); 72 | roadlingt = (Button) itemView.findViewById(R.id.roadlight); 73 | location = (Button) itemView.findViewById(R.id.location); 74 | narrowBtn.setOnClickListener(this); 75 | enlargeBtn.setOnClickListener(this); 76 | roadlingt.setOnClickListener(this); 77 | location.setOnClickListener(this); 78 | 79 | addView(itemView); 80 | } 81 | 82 | @Override 83 | public void onClick(View v) { 84 | mStatus = mBaiduMap.getMapStatus(); 85 | switch (v.getId()) { 86 | case R.id.enlargeBtn: 87 | mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomTo(mStatus.zoom + 1)); 88 | controlZoomStatus(); 89 | break; 90 | case R.id.narrowBtn: 91 | mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomTo(mStatus.zoom - 1)); 92 | controlZoomStatus(); 93 | break; 94 | case R.id.roadlight: 95 | setTraffic(); 96 | break; 97 | case R.id.location: 98 | setLocation(); 99 | break; 100 | default: 101 | break; 102 | } 103 | 104 | //重新获取地图缩放状态 105 | mStatus = mBaiduMap.getMapStatus(); 106 | } 107 | 108 | private void setTraffic() { 109 | if (mBaiduMap.isTrafficEnabled()) { 110 | mBaiduMap.setTrafficEnabled(false); 111 | // item.setTitle("实时交通ON"); 112 | roadlingt.setBackgroundResource(R.mipmap.ic_homepage_roadlight); 113 | } else { 114 | mBaiduMap.setTrafficEnabled(true); 115 | roadlingt.setBackgroundResource(R.mipmap.ic_homepage_roadlight_pressed); 116 | // item.setTitle("实时交通OFF"); 117 | } 118 | } 119 | 120 | //控制缩放状态 121 | private void controlZoomStatus() { 122 | float zoom = mBaiduMap.getMapStatus().zoom; 123 | if (zoom >= maxZoomLevel) { 124 | enlargeBtn.setEnabled(false); 125 | } else { 126 | enlargeBtn.setEnabled(true); 127 | } 128 | 129 | if (zoom <= minZoomLevel) { 130 | narrowBtn.setEnabled(false); 131 | } else { 132 | narrowBtn.setEnabled(true); 133 | } 134 | } 135 | 136 | 137 | public void setMapView(MapView mapView) { 138 | mBaiduMap = mapView.getMap(); 139 | mBaiduMap.setOnMapStatusChangeListener(this); 140 | maxZoomLevel = mBaiduMap.getMaxZoomLevel(); 141 | minZoomLevel = mBaiduMap.getMinZoomLevel(); 142 | controlZoomStatus(); 143 | } 144 | 145 | 146 | private void setLocation() { 147 | LatLng lng = new LatLng(mLatitude, mLongitude); 148 | MapStatusUpdate status = MapStatusUpdateFactory.newLatLng(lng); 149 | mBaiduMap.animateMapStatus(status); 150 | } 151 | 152 | 153 | public void setLocation(double mLatitude, double mLongitude) { 154 | this.mLatitude = mLatitude; 155 | this.mLongitude = mLongitude; 156 | } 157 | 158 | /** 159 | * @param mapStatus 160 | */ 161 | @Override 162 | public void onMapStatusChangeStart(MapStatus mapStatus) { 163 | } 164 | 165 | /** 166 | * @param mapStatus 167 | */ 168 | @Override 169 | public void onMapStatusChange(MapStatus mapStatus) { 170 | controlZoomStatus(); 171 | } 172 | 173 | /** 174 | * @param mapStatus 175 | */ 176 | @Override 177 | public void onMapStatusChangeFinish(MapStatus mapStatus) { 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_base_v4_2_1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_base_v4_2_1.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_map_v4_2_1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/arm64-v8a/libBaiduMapSDK_map_v4_2_1.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/arm64-v8a/liblocSDK7a.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/arm64-v8a/liblocSDK7a.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libBDSpeechDecoder_V1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libBDSpeechDecoder_V1.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libBaiduMapSDK_base_v4_2_1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libBaiduMapSDK_base_v4_2_1.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libBaiduMapSDK_map_v4_2_1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libBaiduMapSDK_map_v4_2_1.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libapp_BaiduNaviApplib.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libapp_BaiduNaviApplib.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libapp_BaiduVIlib.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libapp_BaiduVIlib.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libaudiomessage-jni.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libaudiomessage-jni.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libbd_etts.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libbd_etts.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libbds.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libbds.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libbdtts.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libbdtts.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libcurl.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libcurl.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libetts_domain_data_builder.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libetts_domain_data_builder.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libgnustl_shared.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/libgnustl_shared.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/liblocSDK7a.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/liblocSDK7a.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/liblocnaviSDK.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/armeabi/liblocnaviSDK.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86/libBaiduMapSDK_base_v4_2_1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/x86/libBaiduMapSDK_base_v4_2_1.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86/libBaiduMapSDK_map_v4_2_1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/x86/libBaiduMapSDK_map_v4_2_1.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86/liblocSDK7a.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/x86/liblocSDK7a.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86_64/libBaiduMapSDK_base_v4_2_1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/x86_64/libBaiduMapSDK_base_v4_2_1.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86_64/libBaiduMapSDK_map_v4_2_1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/x86_64/libBaiduMapSDK_map_v4_2_1.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86_64/liblocSDK7a.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wuxinxi/BaiduMap/0e956b26a2fbdeb861b9504fe3980cc936613ccb/app/src/main/jniLibs/x86_64/liblocSDK7a.so -------------------------------------------------------------------------------- /app/src/main/res/anim/push_bottom_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/anim/push_bottom_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/enlarge_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/list_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/location_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/narrow_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/roadlingt_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/scale_item_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/search_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/selector_recycler_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/text_line.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 15 | 26 | 27 | 28 | 39 | 40 | 41 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main_custom.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 17 | 18 | 19 | 27 | 28 | 38 | 39 | 50 | 51 |