├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── libs │ ├── AMap3DMap_5.0.0_AMapNavi_5.0.1_AMapSearch_5.0.0_AMapLocation_3.4.0_20170427.jar │ └── Msc.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── test │ │ └── map │ │ └── ExampleInstrumentedTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── test │ │ └── map │ │ ├── App.java │ │ ├── DriveRouteColorfulOverLay.java │ │ ├── MapActivity.java │ │ ├── NavActivity.java │ │ ├── TTSController.java │ │ ├── adapter │ │ ├── MapHistoryListAdapter.java │ │ └── PoiSearchListAdapter.java │ │ ├── fragment │ │ ├── PoiInformationFragment.java │ │ └── PoiSearchPageFragment.java │ │ ├── listener │ │ ├── GeocodeSearchListenerUtil.java │ │ └── MyLocationChangeListenerUtil.java │ │ ├── model │ │ ├── NaviLatLngBean.java │ │ ├── PathPlanDataBean.java │ │ ├── PoiInfoBean.java │ │ └── PoiItemOnclickBean.java │ │ ├── permission │ │ ├── BaseMPermission.java │ │ ├── MPermission.java │ │ └── annotation │ │ │ ├── OnMPermissionDenied.java │ │ │ ├── OnMPermissionGranted.java │ │ │ └── OnMPermissionNeverAskAgain.java │ │ ├── sqlite │ │ ├── MapHistoryBean.java │ │ ├── UserDataBaseOperate.java │ │ └── UserSQLiteOpenHelper.java │ │ └── util │ │ ├── AmapLocationTestUtil.java │ │ ├── LogUtil.java │ │ ├── MapUtil.java │ │ └── OffLineMapUtils.java │ ├── jniLibs │ └── armeabi │ │ ├── libGNaviData.so │ │ ├── libGNaviGuide.so │ │ ├── libGNaviMap.so │ │ ├── libGNaviMapex.so │ │ ├── libGNaviPos.so │ │ ├── libGNaviRoute.so │ │ ├── libGNaviSearch.so │ │ ├── libGNaviUtils.so │ │ ├── libRoadLineRebuildAPI.so │ │ ├── libmsc.so │ │ ├── librtbt800.so │ │ └── libwtbt800.so │ └── res │ ├── GaodeDemo.apk │ ├── GaodeDemo_主页.png │ ├── GaodeDemo_去这里.png │ ├── GaodeDemo_周边搜索.png │ ├── GaodeDemo_导航.png │ ├── GaodeDemo_策略选择.png │ ├── anim │ ├── popup_enter.xml │ ├── popup_exit.xml │ └── translate_poi_frgment.xml │ ├── drawable │ ├── amap_car.png │ ├── amap_end.png │ ├── amap_start.png │ ├── amap_through.png │ ├── bt_search_icon.png │ ├── emotionstore_progresscancelbtn.png │ ├── go_where.png │ ├── go_where_2.png │ ├── ly_frame_line.xml │ ├── map_bt_back.png │ ├── map_bt_bottm_bg_l.png │ ├── map_bt_bottm_bg_w.png │ ├── map_destination_press.xml │ ├── map_go_bg.png │ ├── map_go_where_iv.png │ ├── map_history_go_where_icon.png │ ├── map_history_icon.png │ ├── map_history_list_divider.xml │ ├── map_nav_select.png │ ├── map_poi_search_bg.png │ ├── map_search_bg.png │ ├── nav_start_bg.png │ ├── out_call_icon.png │ ├── phone_book_icon_blue.png │ ├── phone_dial_icon.png │ ├── phone_dial_icon_blue.png │ ├── phone_emergency.png │ ├── po_seekbar.xml │ ├── poi_marker_pressed.png │ ├── setting_list_divider.xml │ └── wel_bt.png │ ├── layout │ ├── activity_map.xml │ ├── activity_nav.xml │ ├── fragment_poi_info.xml │ ├── fragment_poi_search.xml │ ├── map_history_list_item.xml │ └── map_list_item.xml │ ├── mipmap-hdpi │ └── ic_lau.jpg │ ├── mipmap-mdpi │ └── ic_lau.jpg │ ├── mipmap-xhdpi │ └── ic_lau.jpg │ ├── mipmap-xxhdpi │ └── ic_lau.jpg │ ├── mipmap-xxxhdpi │ └── ic_lau.jpg │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── 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/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GaodeMap 2 | 高德地图、导航简单使用(适合初学者) 3 | 4 | 主要实现以下功能: 5 | 6 | 1、地图基本功能 7 | 8 | 2、定位功能 9 | 10 | 3、POi点击功能 11 | 12 | 4、地理编码和逆地理编码 13 | 14 | 5、周边搜索 15 | 16 | 6、路径规划 17 | 18 | 7、导航策略选择 19 | 20 | 8、导航功能 21 | 22 | (本应用基于大屏幕平板做的,未做适配屏幕) 23 | 24 | 详细说明参照 :http://www.demodashi.com/demo/16767.html 25 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.test.map" 8 | minSdkVersion 17 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.1" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | ndk { 14 | //设置支持的SO库架构 15 | abiFilters 'armeabi' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a' 16 | } 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | compile 'com.android.support:appcompat-v7:25.2.0' 32 | compile 'com.android.support.constraint:constraint-layout:1.0.0-beta1' 33 | testCompile 'junit:junit:4.12' 34 | compile 'org.greenrobot:eventbus:3.0.0' 35 | } 36 | -------------------------------------------------------------------------------- /app/libs/AMap3DMap_5.0.0_AMapNavi_5.0.1_AMapSearch_5.0.0_AMapLocation_3.4.0_20170427.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/libs/AMap3DMap_5.0.0_AMapNavi_5.0.1_AMapSearch_5.0.0_AMapLocation_3.4.0_20170427.jar -------------------------------------------------------------------------------- /app/libs/Msc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/libs/Msc.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 C:\Users\Administrator\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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/test/map/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.test.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.itas.itascrv", 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 | 37 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/App.java: -------------------------------------------------------------------------------- 1 | package com.test.map; 2 | 3 | import android.app.Application; 4 | 5 | 6 | /** 7 | * Created by FAN on 2017/2/27. 8 | */ 9 | 10 | public class App extends Application { 11 | @Override 12 | public void onCreate() { 13 | super.onCreate(); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/DriveRouteColorfulOverLay.java: -------------------------------------------------------------------------------- 1 | package com.test.map; 2 | 3 | import android.graphics.Color; 4 | 5 | import com.amap.api.maps.AMap; 6 | import com.amap.api.maps.AMapUtils; 7 | import com.amap.api.maps.CameraUpdateFactory; 8 | import com.amap.api.maps.model.BitmapDescriptor; 9 | import com.amap.api.maps.model.BitmapDescriptorFactory; 10 | import com.amap.api.maps.model.LatLng; 11 | import com.amap.api.maps.model.LatLngBounds; 12 | import com.amap.api.maps.model.Marker; 13 | import com.amap.api.maps.model.MarkerOptions; 14 | import com.amap.api.maps.model.Polyline; 15 | import com.amap.api.maps.model.PolylineOptions; 16 | import com.amap.api.services.core.LatLonPoint; 17 | import com.amap.api.services.route.DrivePath; 18 | import com.amap.api.services.route.DriveStep; 19 | import com.amap.api.services.route.TMC; 20 | import com.test.map.R; 21 | import com.test.map.util.LogUtil; 22 | import com.test.map.util.MapUtil; 23 | 24 | import org.greenrobot.eventbus.EventBus; 25 | 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | 30 | /** 31 | * 导航路线图层类。 32 | */ 33 | public class DriveRouteColorfulOverLay { 34 | 35 | private AMap mAMap; 36 | protected LatLng startPoint, endPoint; 37 | private Marker startMarker, endMarker; 38 | private DrivePath drivePath; 39 | private List throughPointList; 40 | private List throughPointMarkerList = new ArrayList(); 41 | private boolean throughPointMarkerVisible = true; 42 | private List tmcs; 43 | private PolylineOptions mPolylineOptions; 44 | private boolean isColorfulline = true; 45 | private float mWidth = 17; 46 | protected boolean nodeIconVisible = true; 47 | private List mLatLngsOfPath; 48 | protected List stationMarkers = new ArrayList(); 49 | protected List allPolyLines = new ArrayList(); 50 | 51 | public void setIsColorfulline(boolean iscolorfulline) { 52 | this.isColorfulline = iscolorfulline; 53 | } 54 | 55 | /** 56 | * 根据给定的参数,构造一个导航路线图层类对象。 57 | * 58 | * @param amap 地图对象。 59 | * @param path 导航路线规划方案。 60 | * @param start 起点 61 | * @param end 终点 62 | * @param throughPointList 途径点 63 | */ 64 | public DriveRouteColorfulOverLay(AMap amap, DrivePath path, 65 | LatLonPoint start, LatLonPoint end, List throughPointList) { 66 | mAMap = amap; 67 | drivePath = path; 68 | startPoint = MapUtil.convertToLatLng(start); 69 | endPoint = MapUtil.convertToLatLng(end); 70 | this.throughPointList = throughPointList; 71 | int i= drivePath.getTotalTrafficlights(); 72 | EventBus.getDefault().post("红绿灯 "+i+"个"); 73 | LogUtil.e("红路灯个数:"+i); 74 | } 75 | 76 | /** 77 | * 设置路线宽度 78 | * 79 | * @param mWidth 路线宽度,取值范围:大于0 80 | */ 81 | public void setRouteWidth(float mWidth) { 82 | this.mWidth = mWidth; 83 | } 84 | 85 | /** 86 | * 添加驾车路线添加到地图上显示。 87 | */ 88 | public void addToMap() { 89 | initPolylineOptions(); 90 | try { 91 | if (mAMap == null) { 92 | return; 93 | } 94 | 95 | if (mWidth == 0 || drivePath == null) { 96 | return; 97 | } 98 | mLatLngsOfPath = new ArrayList(); 99 | tmcs = new ArrayList(); 100 | List drivePaths = drivePath.getSteps(); 101 | 102 | mPolylineOptions.add(startPoint); 103 | for (DriveStep step : drivePaths) { 104 | List latlonPoints = step.getPolyline(); 105 | List tmclist = step.getTMCs(); 106 | tmcs.addAll(tmclist); 107 | addDrivingStationMarkers(step, convertToLatLng(latlonPoints.get(0))); 108 | for (LatLonPoint latlonpoint : latlonPoints) { 109 | mPolylineOptions.add(convertToLatLng(latlonpoint)); 110 | mLatLngsOfPath.add(convertToLatLng(latlonpoint)); 111 | } 112 | } 113 | mPolylineOptions.add(endPoint); 114 | if (startMarker != null) { 115 | startMarker.remove(); 116 | startMarker = null; 117 | } 118 | if (endMarker != null) { 119 | endMarker.remove(); 120 | endMarker = null; 121 | } 122 | addStartAndEndMarker(); 123 | addThroughPointMarker(); 124 | if (isColorfulline && tmcs.size() > 0) { 125 | colorWayUpdate(tmcs); 126 | } else { 127 | showPolyline(); 128 | } 129 | 130 | } catch (Throwable e) { 131 | e.printStackTrace(); 132 | } 133 | } 134 | 135 | private void addStartAndEndMarker() { 136 | startMarker = mAMap.addMarker((new MarkerOptions()) 137 | .position(startPoint).icon(getStartBitmapDescriptor()) 138 | .title("\u8D77\u70B9")); 139 | endMarker = mAMap.addMarker((new MarkerOptions()).position(endPoint) 140 | .icon(getEndBitmapDescriptor()).title("\u7EC8\u70B9")); 141 | } 142 | 143 | /** 144 | * 初始化线段属性 145 | */ 146 | private void initPolylineOptions() { 147 | 148 | mPolylineOptions = null; 149 | mPolylineOptions = new PolylineOptions(); 150 | mPolylineOptions.color(getDriveColor()).width(mWidth); 151 | } 152 | 153 | private void showPolyline() { 154 | addPolyLine(mPolylineOptions); 155 | } 156 | 157 | private void colorWayUpdate(List tmcSection) { 158 | if (mAMap == null) { 159 | return; 160 | } 161 | if (mLatLngsOfPath == null || mLatLngsOfPath.size() <= 0) { 162 | return; 163 | } 164 | if (tmcSection == null || tmcSection.size() <= 0) { 165 | return; 166 | } 167 | int j = 0; 168 | LatLng startLatLng = mLatLngsOfPath.get(0); 169 | LatLng endLatLng = null; 170 | double segmentTotalDistance = 0; 171 | TMC segmentTrafficStatus; 172 | List tempList = new ArrayList(); 173 | //画出起点到规划路径之间的连线 174 | addPolyLine(new PolylineOptions().add(startPoint, startLatLng) 175 | .setDottedLine(true)); 176 | //终点和规划路径之间连线 177 | addPolyLine(new PolylineOptions().add(mLatLngsOfPath.get(mLatLngsOfPath.size() - 1), 178 | endPoint).setDottedLine(true)); 179 | for (int i = 0; i < mLatLngsOfPath.size() && j < tmcSection.size(); i++) { 180 | segmentTrafficStatus = tmcSection.get(j); 181 | endLatLng = mLatLngsOfPath.get(i); 182 | double distanceBetweenTwoPosition = AMapUtils.calculateLineDistance(startLatLng, endLatLng); 183 | segmentTotalDistance = segmentTotalDistance + distanceBetweenTwoPosition; 184 | if (segmentTotalDistance > segmentTrafficStatus.getDistance() + 1) { 185 | double toSegDis = distanceBetweenTwoPosition - (segmentTotalDistance - segmentTrafficStatus.getDistance()); 186 | LatLng middleLatLng = getPointForDis(startLatLng, endLatLng, toSegDis); 187 | tempList.add(middleLatLng); 188 | startLatLng = middleLatLng; 189 | i--; 190 | } else { 191 | tempList.add(endLatLng); 192 | startLatLng = endLatLng; 193 | } 194 | if (segmentTotalDistance >= segmentTrafficStatus.getDistance() || i == mLatLngsOfPath.size() - 1) { 195 | if (j == tmcSection.size() - 1 && i < mLatLngsOfPath.size() - 1) { 196 | for (i++; i < mLatLngsOfPath.size(); i++) { 197 | LatLng lastLatLng = mLatLngsOfPath.get(i); 198 | tempList.add(lastLatLng); 199 | } 200 | } 201 | j++; 202 | if (segmentTrafficStatus.getStatus().equals("畅通")) { 203 | addPolyLine((new PolylineOptions()).addAll(tempList) 204 | .width(mWidth).color(Color.GREEN)); 205 | } else if (segmentTrafficStatus.getStatus().equals("缓行")) { 206 | addPolyLine((new PolylineOptions()).addAll(tempList) 207 | .width(mWidth).color(Color.YELLOW)); 208 | } else if (segmentTrafficStatus.getStatus().equals("拥堵")) { 209 | addPolyLine((new PolylineOptions()).addAll(tempList) 210 | .width(mWidth).color(Color.RED)); 211 | } else if (segmentTrafficStatus.getStatus().equals("严重拥堵")) { 212 | addPolyLine((new PolylineOptions()).addAll(tempList) 213 | .width(mWidth).color(Color.parseColor("#990033"))); 214 | } else { 215 | addPolyLine((new PolylineOptions()).addAll(tempList) 216 | .width(mWidth).color(Color.parseColor("#537edc"))); 217 | } 218 | tempList.clear(); 219 | tempList.add(startLatLng); 220 | segmentTotalDistance = 0; 221 | } 222 | if (i == mLatLngsOfPath.size() - 1) { 223 | addPolyLine(new PolylineOptions().add(endLatLng, endPoint) 224 | .setDottedLine(true)); 225 | } 226 | } 227 | } 228 | 229 | private LatLng convertToLatLng(LatLonPoint point) { 230 | return new LatLng(point.getLatitude(), point.getLongitude()); 231 | } 232 | 233 | /** 234 | * @param driveStep 235 | * @param latLng 236 | */ 237 | private void addDrivingStationMarkers(DriveStep driveStep, LatLng latLng) { 238 | MarkerOptions options = new MarkerOptions().position(latLng) 239 | .title("\u65B9\u5411:" + driveStep.getAction() 240 | + "\n\u9053\u8DEF:" + driveStep.getRoad()) 241 | .snippet(driveStep.getInstruction()).visible(nodeIconVisible) 242 | .anchor(0.5f, 0.5f).icon(getDriveBitmapDescriptor()); 243 | if (options == null) { 244 | return; 245 | } 246 | Marker marker = mAMap.addMarker(options); 247 | if (marker != null) { 248 | stationMarkers.add(marker); 249 | } 250 | } 251 | 252 | private LatLngBounds getLatLngBounds() { 253 | LatLngBounds.Builder b = LatLngBounds.builder(); 254 | b.include(new LatLng(startPoint.latitude, startPoint.longitude)); 255 | b.include(new LatLng(endPoint.latitude, endPoint.longitude)); 256 | if (this.throughPointList != null && this.throughPointList.size() > 0) { 257 | for (int i = 0; i < this.throughPointList.size(); i++) { 258 | b.include(new LatLng( 259 | this.throughPointList.get(i).getLatitude(), 260 | this.throughPointList.get(i).getLongitude())); 261 | } 262 | } 263 | return b.build(); 264 | } 265 | 266 | 267 | private void addThroughPointMarker() { 268 | if (this.throughPointList != null && this.throughPointList.size() > 0) { 269 | LatLonPoint latLonPoint = null; 270 | for (int i = 0; i < this.throughPointList.size(); i++) { 271 | latLonPoint = this.throughPointList.get(i); 272 | if (latLonPoint != null) { 273 | throughPointMarkerList.add(mAMap.addMarker(new MarkerOptions() 274 | .position(new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude())) 275 | .visible(throughPointMarkerVisible) 276 | .icon(getThroughPointBitDes()) 277 | .title("\u9014\u7ECF\u70B9"))); 278 | } 279 | } 280 | } 281 | } 282 | 283 | private BitmapDescriptor getThroughPointBitDes() { 284 | return BitmapDescriptorFactory.fromResource(R.drawable.amap_through); 285 | 286 | } 287 | 288 | private BitmapDescriptor getDriveBitmapDescriptor() { 289 | return BitmapDescriptorFactory.fromResource(R.drawable.amap_car); 290 | } 291 | 292 | /** 293 | * 给起点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。 294 | * 295 | * @return 更换的Marker图片。 296 | */ 297 | private BitmapDescriptor getStartBitmapDescriptor() { 298 | return BitmapDescriptorFactory.fromResource(R.drawable.amap_start); 299 | } 300 | 301 | /** 302 | * 给终点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。 303 | * 304 | * @return 更换的Marker图片。 305 | */ 306 | private BitmapDescriptor getEndBitmapDescriptor() { 307 | return BitmapDescriptorFactory.fromResource(R.drawable.amap_end); 308 | } 309 | 310 | private void addPolyLine(PolylineOptions options) { 311 | if (options == null) { 312 | return; 313 | } 314 | Polyline polyline = mAMap.addPolyline(options); 315 | if (polyline != null) { 316 | allPolyLines.add(polyline); 317 | } 318 | } 319 | 320 | private int getDriveColor() { 321 | return Color.parseColor("#537edc"); 322 | } 323 | 324 | private LatLng getPointForDis(LatLng sPt, LatLng ePt, double dis) { 325 | double lSegLength = AMapUtils.calculateLineDistance(sPt, ePt); 326 | double preResult = dis / lSegLength; 327 | return new LatLng((ePt.latitude - sPt.latitude) * preResult + sPt.latitude, (ePt.longitude - sPt.longitude) * preResult + sPt.longitude); 328 | } 329 | 330 | public void setThroughPointIconVisibility(boolean visible) { 331 | try { 332 | throughPointMarkerVisible = visible; 333 | if (this.throughPointMarkerList != null 334 | && this.throughPointMarkerList.size() > 0) { 335 | for (int i = 0; i < this.throughPointMarkerList.size(); i++) { 336 | this.throughPointMarkerList.get(i).setVisible(visible); 337 | } 338 | } 339 | } catch (Throwable e) { 340 | e.printStackTrace(); 341 | } 342 | } 343 | 344 | /** 345 | * 移动镜头到当前的视角。 346 | * 347 | * @since V2.1.0 348 | */ 349 | public void zoomToSpan() { 350 | if (startPoint != null) { 351 | if (mAMap == null) 352 | return; 353 | try { 354 | LatLngBounds bounds = getLatLngBounds(); 355 | mAMap.animateCamera(CameraUpdateFactory 356 | .newLatLngBounds(bounds, 50)); 357 | } catch (Throwable e) { 358 | e.printStackTrace(); 359 | } 360 | } 361 | } 362 | 363 | /** 364 | * 路段节点图标控制显示接口。 365 | * 366 | * @param visible true为显示节点图标,false为不显示。 367 | * @since V2.3.1 368 | */ 369 | public void setNodeIconVisibility(boolean visible) { 370 | try { 371 | nodeIconVisible = visible; 372 | if (this.stationMarkers != null && this.stationMarkers.size() > 0) { 373 | for (int i = 0; i < this.stationMarkers.size(); i++) { 374 | this.stationMarkers.get(i).setVisible(visible); 375 | } 376 | } 377 | } catch (Throwable e) { 378 | e.printStackTrace(); 379 | } 380 | } 381 | 382 | /** 383 | * 去掉DriveLineOverlay上的线段和标记。 384 | */ 385 | public void removeFromMap() { 386 | try { 387 | if (startMarker != null) { 388 | startMarker.remove(); 389 | 390 | } 391 | if (endMarker != null) { 392 | endMarker.remove(); 393 | } 394 | for (Marker marker : stationMarkers) { 395 | marker.remove(); 396 | } 397 | for (Polyline line : allPolyLines) { 398 | line.remove(); 399 | } 400 | if (this.throughPointMarkerList != null 401 | && this.throughPointMarkerList.size() > 0) { 402 | for (int i = 0; i < this.throughPointMarkerList.size(); i++) { 403 | this.throughPointMarkerList.get(i).remove(); 404 | } 405 | this.throughPointMarkerList.clear(); 406 | } 407 | } catch (Throwable e) { 408 | e.printStackTrace(); 409 | } 410 | } 411 | 412 | } -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/MapActivity.java: -------------------------------------------------------------------------------- 1 | package com.test.map; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.app.FragmentManager; 6 | import android.app.FragmentTransaction; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.graphics.BitmapFactory; 10 | import android.os.Bundle; 11 | import android.os.Handler; 12 | import android.os.Message; 13 | import android.support.annotation.NonNull; 14 | import android.support.annotation.Nullable; 15 | import android.view.KeyEvent; 16 | import android.view.MotionEvent; 17 | import android.view.View; 18 | import android.view.Window; 19 | import android.view.WindowManager; 20 | import android.view.inputmethod.InputMethodManager; 21 | import android.widget.Button; 22 | import android.widget.EditText; 23 | import android.widget.ImageView; 24 | import android.widget.Toast; 25 | 26 | import com.amap.api.maps.AMap; 27 | import com.amap.api.maps.CameraUpdateFactory; 28 | import com.amap.api.maps.MapView; 29 | import com.amap.api.maps.MapsInitializer; 30 | import com.amap.api.maps.UiSettings; 31 | import com.amap.api.maps.model.BitmapDescriptorFactory; 32 | import com.amap.api.maps.model.LatLng; 33 | import com.amap.api.maps.model.MarkerOptions; 34 | import com.amap.api.maps.model.MyLocationStyle; 35 | import com.amap.api.maps.model.Poi; 36 | import com.amap.api.navi.model.NaviLatLng; 37 | import com.amap.api.services.core.LatLonPoint; 38 | import com.amap.api.services.geocoder.GeocodeSearch; 39 | import com.amap.api.services.geocoder.RegeocodeQuery; 40 | import com.amap.api.services.route.BusRouteResult; 41 | import com.amap.api.services.route.DrivePath; 42 | import com.amap.api.services.route.DriveRouteResult; 43 | import com.amap.api.services.route.RideRouteResult; 44 | import com.amap.api.services.route.RouteSearch; 45 | import com.amap.api.services.route.WalkRouteResult; 46 | import com.test.map.model.NaviLatLngBean; 47 | import com.test.map.model.PathPlanDataBean; 48 | import com.test.map.model.PoiInfoBean; 49 | import com.test.map.model.PoiItemOnclickBean; 50 | import com.test.map.fragment.PoiInformationFragment; 51 | import com.test.map.fragment.PoiSearchPageFragment; 52 | import com.test.map.listener.GeocodeSearchListenerUtil; 53 | import com.test.map.listener.MyLocationChangeListenerUtil; 54 | import com.test.map.permission.MPermission; 55 | import com.test.map.permission.annotation.OnMPermissionDenied; 56 | import com.test.map.permission.annotation.OnMPermissionGranted; 57 | import com.test.map.permission.annotation.OnMPermissionNeverAskAgain; 58 | import com.test.map.sqlite.MapHistoryBean; 59 | import com.test.map.sqlite.UserDataBaseOperate; 60 | import com.test.map.sqlite.UserSQLiteOpenHelper; 61 | import com.test.map.util.LogUtil; 62 | import com.test.map.util.MapUtil; 63 | import com.test.map.util.OffLineMapUtils; 64 | 65 | import org.greenrobot.eventbus.EventBus; 66 | import org.greenrobot.eventbus.Subscribe; 67 | import org.greenrobot.eventbus.ThreadMode; 68 | 69 | import java.util.List; 70 | 71 | /** 72 | * Created by FAN on 2017/5/8. 73 | */ 74 | 75 | public class MapActivity extends Activity implements AMap.OnPOIClickListener, RouteSearch.OnRouteSearchListener { 76 | private final int BASIC_PERMISSION_REQUEST_CODE = 100; 77 | private FragmentManager mManager; 78 | PoiInformationFragment poiinfoFragment; 79 | PoiSearchPageFragment poiSearchPageFragment; 80 | // 主控件 81 | private MapView mapView; 82 | private AMap aMap; 83 | private MyLocationStyle myLocationStyle; 84 | private GeocodeSearchListenerUtil geocodeSearchListenerUtil; 85 | public static LatLng poiLatLng; 86 | private UiSettings mUiSettings; 87 | private Button bt_back; 88 | private ImageView go_where; 89 | 90 | //发送给information 的信息 91 | public static LatLonPoint mLatLonPoint; 92 | public static String PoiName; 93 | public static String PoiAddress; 94 | public static String PoiDistance; 95 | 96 | public static LatLonPoint infoLatLonPoint; 97 | public static String infoPoiName; 98 | //以下为路径规划 99 | private RouteSearch mRouteSearch; 100 | private DriveRouteResult mDriveRouteResult; 101 | 102 | public static int TEXT_GO_MODE = 0; 103 | private UserSQLiteOpenHelper userSQLiteOpenHelper; 104 | private UserDataBaseOperate userDataBaseOperate; 105 | public static List mapHistoryBeenList; 106 | 107 | @Override 108 | protected void onCreate(@Nullable Bundle savedInstanceState) { 109 | super.onCreate(savedInstanceState); 110 | this.requestWindowFeature(Window.FEATURE_NO_TITLE); 111 | this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 112 | WindowManager.LayoutParams.FLAG_FULLSCREEN); 113 | setContentView(R.layout.activity_map); 114 | MapsInitializer.sdcardDir= OffLineMapUtils.getSdCacheDir(this); 115 | mManager = getFragmentManager(); 116 | mapView = (MapView) findViewById(R.id.map); 117 | mapView.onCreate(savedInstanceState);// 此方法必须重写 118 | init(); 119 | initUi(); 120 | geocodeSearchListenerUtil = new GeocodeSearchListenerUtil(this); 121 | initFragment(); 122 | if (!EventBus.getDefault().isRegistered(this)) { 123 | EventBus.getDefault().register(this); 124 | } 125 | userSQLiteOpenHelper = UserSQLiteOpenHelper.getInstance(this); 126 | userDataBaseOperate = new UserDataBaseOperate(userSQLiteOpenHelper.getWritableDatabase()); 127 | mapHistoryBeenList = userDataBaseOperate.findAll(); 128 | } 129 | 130 | private void initUi() { 131 | bt_back = (Button) findViewById(R.id.bt_back); 132 | go_where = (ImageView) findViewById(R.id.go_where); 133 | } 134 | 135 | /** 136 | * 初始化AMap对象 137 | */ 138 | private void init() { 139 | if (aMap == null) { 140 | aMap = mapView.getMap(); 141 | mUiSettings = aMap.getUiSettings(); 142 | setUpMap(); 143 | } 144 | //设置SDK 自带定位消息监听 145 | aMap.setOnMyLocationChangeListener(MyLocationChangeListenerUtil.getInstance(this)); 146 | aMap.setOnPOIClickListener(this); 147 | mUiSettings.setRotateGesturesEnabled(false); 148 | //初始化路径搜索 149 | mRouteSearch = new RouteSearch(this); 150 | mRouteSearch.setRouteSearchListener(this); //路径规划事件监听 151 | } 152 | 153 | /** 154 | * 设置一些amap的属性 155 | */ 156 | private void setUpMap() { 157 | // 如果要设置定位的默认状态,可以在此处进行设置 158 | myLocationStyle = new MyLocationStyle(); 159 | aMap.setMyLocationStyle(myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE)); 160 | aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示 161 | aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false 162 | } 163 | 164 | private void initFragment() { 165 | poiinfoFragment = new PoiInformationFragment(); 166 | poiSearchPageFragment = new PoiSearchPageFragment(); 167 | } 168 | 169 | public void Enter_SearchPage(View view) { 170 | addSearchPageFragment(); 171 | // addBackMap(); 172 | hideGoWhere(); 173 | } 174 | 175 | /** 176 | * poi 搜索返回到地图界面 177 | * 178 | * @param view 179 | */ 180 | public void Back_Map(View view) { 181 | if (poiSearchPageFragment.isAdded()) { 182 | removeSearchPageFragment(); 183 | } 184 | if (poiinfoFragment.isAdded()) { 185 | removePoiInfoFragment(); 186 | } 187 | hideBackMap(); 188 | addGoWhere(); 189 | clearMap(); 190 | startLocation(); 191 | } 192 | 193 | /** 194 | * 方法必须重写 195 | */ 196 | @Override 197 | protected void onResume() { 198 | super.onResume(); 199 | mapView.onResume(); 200 | startLocation(); 201 | } 202 | 203 | /** 204 | * 方法必须重写 205 | */ 206 | @Override 207 | protected void onPause() { 208 | super.onPause(); 209 | mapView.onPause(); 210 | } 211 | 212 | /** 213 | * 方法必须重写 214 | */ 215 | @Override 216 | protected void onSaveInstanceState(Bundle outState) { 217 | super.onSaveInstanceState(outState); 218 | mapView.onSaveInstanceState(outState); 219 | } 220 | 221 | /** 222 | * 方法必须重写 223 | */ 224 | @Override 225 | protected void onDestroy() { 226 | super.onDestroy(); 227 | mapView.onDestroy(); 228 | EventBus.getDefault().unregister(this); 229 | } 230 | 231 | @Override 232 | public void onPOIClick(Poi poi) { 233 | if (poiSearchPageFragment.isAdded()) 234 | return; 235 | aMap.clear(); 236 | poiLatLng = poi.getCoordinate(); //得到poi的LatLng 值 237 | infoPoiName = poi.getName(); 238 | MarkerOptions markOptiopns = new MarkerOptions(); 239 | markOptiopns.position(poi.getCoordinate()); 240 | markOptiopns.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.poi_marker_pressed))); 241 | aMap.addMarker(markOptiopns); 242 | LogUtil.e("" + poi.toString()); 243 | mLatLonPoint = MapUtil.convertToLatLonPoint(poi.getCoordinate()); 244 | aMap.animateCamera(CameraUpdateFactory.newLatLngZoom( 245 | MapUtil.convertToLatLng(mLatLonPoint), 15)); 246 | getAddress(mLatLonPoint); 247 | addPoiInfoFragment(); 248 | addBackMap(); 249 | hideGoWhere(); 250 | EventBus.getDefault().post("查看poi信息界面是否在算路界面"); 251 | } 252 | 253 | /** 254 | * 响应逆地理编码 255 | */ 256 | public void getAddress(final LatLonPoint latLonPoint) { 257 | RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200, 258 | GeocodeSearch.AMAP);// 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系 259 | GeocodeSearchListenerUtil.geocoderSearch.getFromLocationAsyn(query);// 设置异步逆地理编码请求 260 | } 261 | 262 | /** 263 | * 显示poi信息Fragment 264 | */ 265 | private void addPoiInfoFragment() { 266 | if (poiinfoFragment.isAdded()) 267 | return; 268 | FragmentTransaction ft = mManager.beginTransaction(); 269 | ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 270 | ft.add(R.id.poi_info, poiinfoFragment); 271 | ft.commit(); 272 | } 273 | 274 | /** 275 | * 移除poi信息Fragment 276 | */ 277 | private void removePoiInfoFragment() { 278 | FragmentTransaction ft = mManager.beginTransaction(); 279 | ft.remove(poiinfoFragment); 280 | ft.commit(); 281 | } 282 | 283 | /** 284 | * 显示搜索页面的Fragment 285 | */ 286 | private void addSearchPageFragment() { 287 | if (poiSearchPageFragment.isAdded()) 288 | return; 289 | FragmentTransaction ft = mManager.beginTransaction(); 290 | ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 291 | ft.add(R.id.search_page, poiSearchPageFragment); 292 | ft.commit(); 293 | } 294 | 295 | /** 296 | * 移除搜索页面的Fragment 297 | */ 298 | private void removeSearchPageFragment() { 299 | FragmentTransaction ft = mManager.beginTransaction(); 300 | ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 301 | ft.remove(poiSearchPageFragment); 302 | ft.commit(); 303 | } 304 | 305 | /** 306 | * 导航Fragment已打开 307 | */ 308 | private void StartNav() { 309 | Double a = MapUtil.latLonPoint.getLatitude(); 310 | Double b = MapUtil.latLonPoint.getLongitude(); 311 | Double c = poiLatLng.latitude; 312 | Double d = poiLatLng.longitude; 313 | NaviLatLng satrtNaviLatLng = new NaviLatLng(a, b); 314 | NaviLatLng stopNaviLatLng = new NaviLatLng(c, d); 315 | NaviLatLngBean naviLatLngBean = new NaviLatLngBean(satrtNaviLatLng, stopNaviLatLng); 316 | EventBus.getDefault().post(naviLatLngBean); 317 | } 318 | 319 | /** 320 | * 显现 目的地 321 | */ 322 | private void addGoWhere() { 323 | go_where.setVisibility(View.VISIBLE); 324 | } 325 | 326 | /** 327 | * 隐藏 目的地 328 | */ 329 | private void hideGoWhere() { 330 | go_where.setVisibility(View.GONE); 331 | } 332 | 333 | /** 334 | * 显现 返回地图 335 | */ 336 | private void addBackMap() { 337 | bt_back.setVisibility(View.VISIBLE); 338 | } 339 | 340 | /** 341 | * 隐藏 返回地图 342 | */ 343 | private void hideBackMap() { 344 | bt_back.setVisibility(View.GONE); 345 | } 346 | 347 | /** 348 | * Amap Clear 349 | */ 350 | private void clearMap() { 351 | aMap.clear(); 352 | } 353 | 354 | /** 355 | * 开始定位 356 | */ 357 | private void startLocation() { 358 | setUpMap(); 359 | } 360 | 361 | 362 | /** 363 | * EventBus 接收 364 | */ 365 | 366 | @Subscribe(threadMode = ThreadMode.MAIN) 367 | public void onEvent(PoiItemOnclickBean poiItemOnclickBean) { 368 | addPoiInfoFragment(); 369 | removeSearchPageFragment(); 370 | hideBackMap(); 371 | mLatLonPoint = poiItemOnclickBean.getLatLonPoint(); 372 | poiLatLng = MapUtil.convertToLatLng(mLatLonPoint); 373 | LatLng latLng = MapUtil.convertToLatLng(mLatLonPoint); 374 | //虽然 数据传输过来 但是 目前也只是用到了经纬度,在PoiInformationFragment 中用到其他 数据 375 | MarkerOptions markOptiopns = new MarkerOptions(); 376 | markOptiopns.position(latLng); 377 | markOptiopns.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.poi_marker_pressed))); 378 | aMap.addMarker(markOptiopns); 379 | aMap.animateCamera(CameraUpdateFactory.newLatLngZoom( 380 | MapUtil.convertToLatLng(mLatLonPoint), 15)); 381 | PoiName = poiItemOnclickBean.getPoi_Name(); 382 | PoiAddress = poiItemOnclickBean.getPoi_Address(); 383 | PoiDistance = poiItemOnclickBean.getPoi_Distance(); 384 | mHandler.sendEmptyMessageDelayed(SEND_HANDLE, 1000); 385 | } 386 | /** 387 | * EventBus 接收 388 | */ 389 | 390 | @Subscribe(threadMode = ThreadMode.MAIN) 391 | public void onEvent(MapHistoryBean mapHistoryBean) { 392 | userDataBaseOperate.insertToHistory(mapHistoryBean); 393 | mapHistoryBeenList = userDataBaseOperate.findAll(); 394 | } 395 | @Subscribe(threadMode = ThreadMode.MAIN) 396 | public void onEvent(String msg) { 397 | if (msg.equalsIgnoreCase("back_map")) { 398 | Back_Map(null); 399 | } else if (msg.equalsIgnoreCase("默认")) { 400 | searchRouteResult(RouteSearch.DRIVING_SINGLE_DEFAULT); 401 | TEXT_GO_MODE = 1; 402 | MapUtil.PathPlanningMode = 0; 403 | } else if (msg.equalsIgnoreCase("距离最短")) { 404 | searchRouteResult(RouteSearch.DRIVING_SINGLE_SHORTEST); 405 | MapUtil.PathPlanningMode = 1; 406 | } else if (msg.equalsIgnoreCase("避免拥堵")) { 407 | MapUtil.PathPlanningMode = 2; 408 | searchRouteResult(RouteSearch.DRIVING_SINGLE_AVOID_CONGESTION); 409 | } else if (msg.equalsIgnoreCase("开始导航")) { 410 | removePoiInfoFragment(); 411 | Back_Map(null); 412 | Intent intent = new Intent(); 413 | intent.setClass(this, NavActivity.class); 414 | startActivity(intent); 415 | mHandler.sendEmptyMessageDelayed(SEND_NAV_DATA, 1000); 416 | }else if (msg.equalsIgnoreCase("ClearMapHistory")){ 417 | userDataBaseOperate.deleteAll(); 418 | mapHistoryBeenList = userDataBaseOperate.findAll(); 419 | EventBus.getDefault().post("HistoryNull"); 420 | } 421 | } 422 | 423 | /** 424 | * 开始搜索路径规划方案 425 | */ 426 | public void searchRouteResult(int mode) { 427 | 428 | if (MapUtil.latLonPoint == null) { 429 | Toast.makeText(getApplicationContext(), "定位中,稍后再试...", Toast.LENGTH_SHORT).show(); 430 | return; 431 | } 432 | if (mLatLonPoint == null) { 433 | Toast.makeText(getApplicationContext(), "终点未设置", Toast.LENGTH_SHORT).show(); 434 | return; 435 | } 436 | final RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo( 437 | MapUtil.latLonPoint, mLatLonPoint); 438 | // 驾车路径规划 439 | RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, mode, null, 440 | null, "");// 第一个参数表示路径规划的起点和终点,第二个参数表示驾车模式,第三个参数表示途经点,第四个参数表示避让区域,第五个参数表示避让道路 441 | mRouteSearch.calculateDriveRouteAsyn(query);// 异步路径规划驾车模式查询 442 | 443 | } 444 | 445 | /** 446 | * 路径规划 447 | * 448 | * @param busRouteResult 449 | * @param i 450 | */ 451 | @Override 452 | public void onBusRouteSearched(BusRouteResult busRouteResult, int i) { 453 | 454 | } 455 | 456 | @Override 457 | public void onDriveRouteSearched(DriveRouteResult result, int errorCode) { 458 | clearMap(); 459 | if (errorCode == 1000) { 460 | if (result != null && result.getPaths() != null) { 461 | if (result.getPaths().size() > 0) { 462 | mDriveRouteResult = result; 463 | final DrivePath drivePath = mDriveRouteResult.getPaths() 464 | .get(0); 465 | DriveRouteColorfulOverLay drivingRouteOverlay = new DriveRouteColorfulOverLay( 466 | aMap, drivePath, 467 | mDriveRouteResult.getStartPos(), 468 | mDriveRouteResult.getTargetPos(), null); 469 | drivingRouteOverlay.setNodeIconVisibility(false);//设置节点marker是否显示 470 | drivingRouteOverlay.setIsColorfulline(true);//是否用颜色展示交通拥堵情况,默认true 471 | drivingRouteOverlay.removeFromMap(); 472 | drivingRouteOverlay.addToMap(); 473 | drivingRouteOverlay.zoomToSpan(); 474 | 475 | int dis = (int) drivePath.getDistance(); 476 | int dur = (int) drivePath.getDuration(); 477 | if (MapUtil.PathPlanningMode == 0) { 478 | MapUtil.DRIVING_SINGLE_DEFAULT_TIME = MapUtil.getFriendlyTime(dur) ; 479 | MapUtil.DRIVING_SINGLE_DEFAULT_DISTANCE = MapUtil.getFriendlyLength(dis); 480 | PathPlanDataBean pathPlanDataBean = new PathPlanDataBean(MapUtil.DRIVING_SINGLE_DEFAULT_TIME, MapUtil.DRIVING_SINGLE_DEFAULT_DISTANCE); 481 | EventBus.getDefault().post(pathPlanDataBean); 482 | } else if (MapUtil.PathPlanningMode == 1) { 483 | MapUtil.DRIVING_SINGLE_SHORTEST_TIME = MapUtil.getFriendlyTime(dur); 484 | MapUtil.DRIVING_SINGLE_SHORTEST_DISTANCE = MapUtil.getFriendlyLength(dis); 485 | PathPlanDataBean pathPlanDataBean = new PathPlanDataBean(MapUtil.DRIVING_SINGLE_SHORTEST_TIME, MapUtil.DRIVING_SINGLE_SHORTEST_DISTANCE); 486 | EventBus.getDefault().post(pathPlanDataBean); 487 | } else if (MapUtil.PathPlanningMode == 2) { 488 | MapUtil.DRIVING_SINGLE_AVOID_CONGESTION_TIME = MapUtil.getFriendlyTime(dur); 489 | MapUtil.DRIVING_SINGLE_AVOID_CONGESTION_DISTANCE = MapUtil.getFriendlyLength(dis); 490 | PathPlanDataBean pathPlanDataBean = new PathPlanDataBean(MapUtil.DRIVING_SINGLE_AVOID_CONGESTION_TIME, MapUtil.DRIVING_SINGLE_AVOID_CONGESTION_DISTANCE); 491 | EventBus.getDefault().post(pathPlanDataBean); 492 | } 493 | 494 | } else if (result != null && result.getPaths() == null) { 495 | Toast.makeText(getApplication(), "无返回结果", Toast.LENGTH_SHORT).show(); 496 | } 497 | 498 | } else { 499 | Toast.makeText(getApplication(), "无返回结果", Toast.LENGTH_SHORT).show(); 500 | } 501 | } else { 502 | // rCodeGaoDe(errorCode); 503 | } 504 | } 505 | 506 | @Override 507 | public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int i) { 508 | 509 | } 510 | 511 | @Override 512 | public void onRideRouteSearched(RideRouteResult rideRouteResult, int i) { 513 | 514 | } 515 | 516 | 517 | public static final int SEND_HANDLE = 1; 518 | public static final int SEND_NAV_DATA = 2; 519 | private Handler mHandler = new Handler() { 520 | @Override 521 | public void dispatchMessage(Message msg) { 522 | switch (msg.what) { 523 | case SEND_HANDLE: 524 | PoiInfoBean poiInfoBean = new PoiInfoBean(PoiName, PoiAddress, PoiDistance, mLatLonPoint); 525 | EventBus.getDefault().post(poiInfoBean); 526 | break; 527 | case SEND_NAV_DATA: 528 | StartNav(); 529 | break; 530 | } 531 | } 532 | }; 533 | 534 | 535 | //========================================================================================================================= 536 | 537 | /** 538 | * 隐藏输入框 判断 539 | * 540 | * @param v 541 | * @param event 542 | * @return 543 | */ 544 | public boolean isShouldHideInput(View v, MotionEvent event) { 545 | if (v != null && (v instanceof EditText)) { 546 | int[] leftTop = {0, 0}; 547 | //获取输入框当前的location位置 548 | v.getLocationInWindow(leftTop); 549 | int left = leftTop[0]; 550 | int top = leftTop[1]; 551 | int bottom = top + v.getHeight(); 552 | int right = left + v.getWidth(); 553 | if (event.getX() > left && event.getX() < right 554 | && event.getY() > top && event.getY() < bottom) { 555 | // 点击的是输入框区域,保留点击EditText的事件 556 | return false; 557 | } else { 558 | return true; 559 | } 560 | } 561 | return false; 562 | } 563 | 564 | /** 565 | * 隐藏输入框 566 | * 567 | * @param ev 568 | * @return 569 | */ 570 | @Override 571 | public boolean dispatchTouchEvent(MotionEvent ev) { 572 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { 573 | View v = getCurrentFocus(); 574 | if (isShouldHideInput(v, ev)) { 575 | 576 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 577 | if (imm != null) { 578 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0); 579 | } 580 | } 581 | return super.dispatchTouchEvent(ev); 582 | } 583 | // 必不可少,否则所有的组件都不会有TouchEvent了 584 | if (getWindow().superDispatchTouchEvent(ev)) { 585 | return true; 586 | } 587 | return onTouchEvent(ev); 588 | } 589 | 590 | @Override 591 | public boolean onKeyDown(int keyCode, KeyEvent event) { 592 | if (keyCode == KeyEvent.KEYCODE_BACK) { 593 | if (poiinfoFragment.isAdded()) { 594 | removePoiInfoFragment(); 595 | Back_Map(null); 596 | } else if (poiSearchPageFragment.isAdded()) { 597 | removeSearchPageFragment(); 598 | Back_Map(null); 599 | } else { 600 | finish(); 601 | } 602 | } 603 | return false; 604 | } 605 | 606 | 607 | /** 608 | * 基本权限管理 609 | */ 610 | private final String[] BASIC_PERMISSIONS = new String[]{ 611 | Manifest.permission.WRITE_EXTERNAL_STORAGE, 612 | Manifest.permission.READ_CONTACTS, 613 | Manifest.permission.ACCESS_FINE_LOCATION, 614 | Manifest.permission.CALL_PHONE, 615 | }; 616 | private void requestBasicPermission() { 617 | MPermission.printMPermissionResult(true, this, BASIC_PERMISSIONS); 618 | MPermission.with(this) 619 | .setRequestCode(BASIC_PERMISSION_REQUEST_CODE) 620 | .permissions(BASIC_PERMISSIONS) 621 | .request(); 622 | } 623 | 624 | @Override 625 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 626 | MPermission.onRequestPermissionsResult(this, requestCode, permissions, grantResults); 627 | } 628 | 629 | @OnMPermissionGranted(value = BASIC_PERMISSION_REQUEST_CODE) 630 | public void onBasicPermissionSuccess() { 631 | // Toast.makeText(this, "授权成功", Toast.LENGTH_SHORT).show(); 632 | MPermission.printMPermissionResult(false, this, BASIC_PERMISSIONS); 633 | } 634 | 635 | @OnMPermissionDenied(BASIC_PERMISSION_REQUEST_CODE) 636 | @OnMPermissionNeverAskAgain(BASIC_PERMISSION_REQUEST_CODE) 637 | public void onBasicPermissionFailed() { 638 | Toast.makeText(this, "未全部授权,部分功能可能无法正常运行!", Toast.LENGTH_SHORT).show(); 639 | MPermission.printMPermissionResult(false, this, BASIC_PERMISSIONS); 640 | finish(); 641 | } 642 | } 643 | 644 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/NavActivity.java: -------------------------------------------------------------------------------- 1 | package com.test.map; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.view.Window; 7 | import android.view.WindowManager; 8 | 9 | import com.amap.api.maps.UiSettings; 10 | import com.amap.api.navi.AMapNavi; 11 | import com.amap.api.navi.AMapNaviListener; 12 | import com.amap.api.navi.AMapNaviView; 13 | import com.amap.api.navi.AMapNaviViewListener; 14 | import com.amap.api.navi.enums.NaviType; 15 | import com.amap.api.navi.enums.PathPlanningStrategy; 16 | import com.amap.api.navi.model.AMapLaneInfo; 17 | import com.amap.api.navi.model.AMapNaviCameraInfo; 18 | import com.amap.api.navi.model.AMapNaviCross; 19 | import com.amap.api.navi.model.AMapNaviInfo; 20 | import com.amap.api.navi.model.AMapNaviLocation; 21 | import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo; 22 | import com.amap.api.navi.model.AMapServiceAreaInfo; 23 | import com.amap.api.navi.model.AimLessModeCongestionInfo; 24 | import com.amap.api.navi.model.AimLessModeStat; 25 | import com.amap.api.navi.model.NaviInfo; 26 | import com.amap.api.navi.model.NaviLatLng; 27 | import com.autonavi.tbt.TrafficFacilityInfo; 28 | import com.test.map.model.NaviLatLngBean; 29 | import com.test.map.util.LogUtil; 30 | import com.test.map.util.MapUtil; 31 | 32 | import org.greenrobot.eventbus.EventBus; 33 | import org.greenrobot.eventbus.Subscribe; 34 | import org.greenrobot.eventbus.ThreadMode; 35 | 36 | import java.util.ArrayList; 37 | import java.util.List; 38 | 39 | /** 40 | * Created by FAN on 2017/5/8. 41 | */ 42 | 43 | public class NavActivity extends Activity implements AMapNaviViewListener, AMapNaviListener { 44 | TTSController mTtsManager; 45 | AMapNaviView mAMapNaviView; 46 | AMapNavi mAMapNavi; 47 | NaviLatLng mEndLatlng; 48 | NaviLatLng mStartLatlng; 49 | List mStartList = new ArrayList(); 50 | List mEndList = new ArrayList(); 51 | List mWayPointList; 52 | private UiSettings mUiSettings; 53 | 54 | @Override 55 | protected void onCreate(@Nullable Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | this.requestWindowFeature(Window.FEATURE_NO_TITLE); 58 | this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 59 | WindowManager.LayoutParams.FLAG_FULLSCREEN); 60 | setContentView(R.layout.activity_nav); 61 | mAMapNaviView = (AMapNaviView) findViewById(R.id.navi_view); 62 | mAMapNaviView.onCreate(savedInstanceState); 63 | //实例化语音引擎 64 | mTtsManager = TTSController.getInstance(getApplicationContext()); 65 | mTtsManager.init(); 66 | initHudMap(); 67 | MapActivity.TEXT_GO_MODE = 0; 68 | EventBus.getDefault().register(this); 69 | } 70 | 71 | private void initHudMap() { 72 | mAMapNavi = AMapNavi.getInstance(this); 73 | mUiSettings = mAMapNaviView.getMap().getUiSettings(); 74 | mUiSettings.setRotateGesturesEnabled(false); 75 | mAMapNaviView.setAMapNaviViewListener(this); 76 | mAMapNavi.addAMapNaviListener(mTtsManager); 77 | mAMapNavi.addAMapNaviListener(this); 78 | mAMapNavi.setEmulatorNaviSpeed(60); 79 | } 80 | 81 | @Override 82 | protected void onResume() { 83 | super.onResume(); 84 | } 85 | 86 | @Override 87 | protected void onDestroy() { 88 | super.onDestroy(); 89 | mTtsManager.stopSpeaking(); 90 | mAMapNaviView.onDestroy(); 91 | //since 1.6.0 92 | //不再在naviview destroy的时候自动执行AMapNavi.stopNavi(); 93 | //请自行执行 94 | mAMapNavi.stopNavi(); 95 | mAMapNavi.destroy(); 96 | mTtsManager.destroy(); 97 | EventBus.getDefault().unregister(this); 98 | } 99 | 100 | /** 101 | * EventBus 接收 102 | */ 103 | 104 | @Subscribe(threadMode = ThreadMode.MAIN) 105 | public void onEvent(NaviLatLngBean naviLatLngBean) { 106 | mStartLatlng = naviLatLngBean.getStartNaviLatLng(); 107 | mEndLatlng = naviLatLngBean.getStopNaviLatLng(); 108 | startNav(); 109 | } 110 | 111 | private void startNav() { 112 | mStartList.add(mStartLatlng); 113 | mEndList.add(mEndLatlng); 114 | int strategy = 0; 115 | try { 116 | strategy = mAMapNavi.strategyConvert(true, false, false, false, false); 117 | } catch (Exception e) { 118 | e.printStackTrace(); 119 | } 120 | if (MapUtil.PathPlanningMode==0){ 121 | boolean ss = mAMapNavi.calculateDriveRoute(mStartList, mEndList, mWayPointList, PathPlanningStrategy.DRIVING_DEFAULT); 122 | }else if (MapUtil.PathPlanningMode==1){ 123 | boolean ss = mAMapNavi.calculateDriveRoute(mStartList, mEndList, mWayPointList, PathPlanningStrategy.DRIVING_SHORTEST_DISTANCE); 124 | }else if (MapUtil.PathPlanningMode==2){ 125 | boolean ss = mAMapNavi.calculateDriveRoute(mStartList, mEndList, mWayPointList, PathPlanningStrategy.DRIVING_AVOID_CONGESTION); 126 | } 127 | 128 | LogUtil.e("导航策略:" + MapUtil.PathPlanningMode); 129 | } 130 | 131 | @Override 132 | public void onNaviSetting() { 133 | 134 | } 135 | 136 | @Override 137 | public void onNaviCancel() { 138 | 139 | finish(); 140 | } 141 | 142 | @Override 143 | public boolean onNaviBackClick() { 144 | return false; 145 | } 146 | 147 | @Override 148 | public void onNaviMapMode(int i) { 149 | 150 | } 151 | 152 | @Override 153 | public void onNaviTurnClick() { 154 | 155 | } 156 | 157 | @Override 158 | public void onNextRoadClick() { 159 | 160 | } 161 | 162 | @Override 163 | public void onScanViewButtonClick() { 164 | 165 | } 166 | 167 | @Override 168 | public void onLockMap(boolean b) { 169 | 170 | } 171 | 172 | @Override 173 | public void onNaviViewLoaded() { 174 | 175 | } 176 | 177 | @Override 178 | public void onInitNaviFailure() { 179 | 180 | } 181 | 182 | @Override 183 | public void onInitNaviSuccess() { 184 | /** 185 | * 方法: 186 | * int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute); 187 | * 参数: 188 | * @congestion 躲避拥堵 189 | * @avoidhightspeed 不走高速 190 | * @cost 避免收费 191 | * @hightspeed 高速优先 192 | * @multipleroute 多路径 193 | * 194 | * 说明: 195 | * 以上参数都是boolean类型,其中multipleroute参数表示是否多条路线,如果为true则此策略会算出多条路线。 196 | * 注意: 197 | * 不走高速与高速优先不能同时为true 198 | * 高速优先与避免收费不能同时为true 199 | */ 200 | 201 | } 202 | 203 | @Override 204 | public void onStartNavi(int i) { 205 | 206 | } 207 | 208 | @Override 209 | public void onTrafficStatusUpdate() { 210 | 211 | } 212 | 213 | @Override 214 | public void onLocationChange(AMapNaviLocation aMapNaviLocation) { 215 | 216 | } 217 | 218 | @Override 219 | public void onGetNavigationText(int i, String s) { 220 | 221 | } 222 | 223 | @Override 224 | public void onEndEmulatorNavi() { 225 | 226 | } 227 | 228 | @Override 229 | public void onArriveDestination() { 230 | 231 | } 232 | 233 | @Override 234 | public void onCalculateRouteSuccess() { 235 | mAMapNavi.setEmulatorNaviSpeed(60); 236 | AMapNavi.getInstance(this).startNavi(NaviType.EMULATOR); 237 | } 238 | 239 | @Override 240 | public void onCalculateRouteFailure(int i) { 241 | 242 | } 243 | 244 | @Override 245 | public void onReCalculateRouteForYaw() { 246 | 247 | } 248 | 249 | @Override 250 | public void onReCalculateRouteForTrafficJam() { 251 | 252 | } 253 | 254 | @Override 255 | public void onArrivedWayPoint(int i) { 256 | 257 | } 258 | 259 | @Override 260 | public void onGpsOpenStatus(boolean b) { 261 | 262 | } 263 | 264 | @Override 265 | public void onNaviInfoUpdate(NaviInfo naviInfo) { 266 | 267 | } 268 | 269 | @Override 270 | public void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) { 271 | 272 | } 273 | 274 | @Override 275 | public void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) { 276 | 277 | } 278 | 279 | @Override 280 | public void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) { 281 | 282 | } 283 | 284 | @Override 285 | public void showCross(AMapNaviCross aMapNaviCross) { 286 | 287 | } 288 | 289 | @Override 290 | public void hideCross() { 291 | 292 | } 293 | 294 | @Override 295 | public void showLaneInfo(AMapLaneInfo[] aMapLaneInfos, byte[] bytes, byte[] bytes1) { 296 | 297 | } 298 | 299 | @Override 300 | public void hideLaneInfo() { 301 | 302 | } 303 | 304 | @Override 305 | public void onCalculateMultipleRoutesSuccess(int[] ints) { 306 | 307 | } 308 | 309 | @Override 310 | public void notifyParallelRoad(int i) { 311 | 312 | } 313 | 314 | @Override 315 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) { 316 | 317 | } 318 | 319 | @Override 320 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) { 321 | 322 | } 323 | 324 | @Override 325 | public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) { 326 | 327 | } 328 | 329 | @Override 330 | public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) { 331 | 332 | } 333 | 334 | @Override 335 | public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) { 336 | 337 | } 338 | 339 | @Override 340 | public void onPlayRing(int i) { 341 | 342 | } 343 | 344 | 345 | 346 | 347 | /* @Subscribe(threadMode = ThreadMode.MAIN) 348 | public void onEvent(String msg) { 349 | if (msg.equalsIgnoreCase("PhoneComming")) { 350 | Intent intent = new Intent(); 351 | intent.setAction(MyVar.STATICACTION); 352 | sendBroadcast(intent); 353 | } 354 | }*/ 355 | } 356 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/TTSController.java: -------------------------------------------------------------------------------- 1 | package com.test.map; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.os.Message; 7 | import android.widget.Toast; 8 | 9 | import com.amap.api.navi.MyNaviListener; 10 | import com.amap.api.navi.model.AMapLaneInfo; 11 | import com.amap.api.navi.model.AMapNaviCameraInfo; 12 | import com.amap.api.navi.model.AMapNaviCross; 13 | import com.amap.api.navi.model.AMapNaviInfo; 14 | import com.amap.api.navi.model.AMapNaviLocation; 15 | import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo; 16 | import com.amap.api.navi.model.AMapServiceAreaInfo; 17 | import com.amap.api.navi.model.AimLessModeCongestionInfo; 18 | import com.amap.api.navi.model.AimLessModeStat; 19 | import com.amap.api.navi.model.AmapCarLocation; 20 | import com.amap.api.navi.model.NaviInfo; 21 | import com.autonavi.tbt.TrafficFacilityInfo; 22 | import com.iflytek.cloud.ErrorCode; 23 | import com.iflytek.cloud.InitListener; 24 | import com.iflytek.cloud.SpeechConstant; 25 | import com.iflytek.cloud.SpeechError; 26 | import com.iflytek.cloud.SpeechSynthesizer; 27 | import com.iflytek.cloud.SpeechUtility; 28 | import com.iflytek.cloud.SynthesizerListener; 29 | import com.test.map.util.LogUtil; 30 | 31 | import java.util.LinkedList; 32 | 33 | /** 34 | * 当前DEMO的播报方式是队列模式。其原理就是依次将需要播报的语音放入链表中,播报过程是从头开始依次往后播报。 35 | *

36 | * 导航SDK原则上是不提供语音播报模块的,如果您觉得此种播报方式不能满足你的需求,请自行优化或改进。 37 | */ 38 | public class TTSController implements MyNaviListener { 39 | 40 | /** 41 | * 请替换您自己申请的ID。 42 | */ 43 | private final String appId = "59146818"; //59146818 5350db8d 44 | 45 | public static TTSController ttsManager; 46 | private Context mContext; 47 | private SpeechSynthesizer mTts; 48 | private boolean isPlaying = false; 49 | private LinkedList wordList = new LinkedList(); 50 | private final int TTS_PLAY = 1; 51 | private final int CHECK_TTS_PLAY = 2; 52 | private Handler handler = new Handler() { 53 | @Override 54 | public void handleMessage(Message msg) { 55 | super.handleMessage(msg); 56 | switch (msg.what) { 57 | case TTS_PLAY: 58 | synchronized (mTts) { 59 | if (!isPlaying && mTts != null && wordList.size() > 0) { 60 | isPlaying = true; 61 | String playtts = wordList.removeFirst(); 62 | if (mTts == null) { 63 | createSynthesizer(); 64 | } 65 | mTts.startSpeaking(playtts, new SynthesizerListener() { 66 | @Override 67 | public void onCompleted(SpeechError arg0) { 68 | LogUtil.e("onSpeak onCompleted........"); 69 | isPlaying = false; 70 | handler.obtainMessage(1).sendToTarget(); 71 | } 72 | 73 | @Override 74 | public void onEvent(int arg0, int arg1, int arg2, Bundle arg3) { 75 | } 76 | 77 | @Override 78 | public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) { 79 | // 合成进度 80 | isPlaying = true; 81 | 82 | } 83 | 84 | @Override 85 | public void onSpeakBegin() { 86 | //开始播放 87 | isPlaying = true; 88 | LogUtil.e("onSpeakBegin...."); 89 | } 90 | 91 | @Override 92 | public void onSpeakPaused() { 93 | 94 | } 95 | 96 | @Override 97 | public void onSpeakProgress(int arg0, int arg1, int arg2) { 98 | //播放进度 99 | isPlaying = true; 100 | } 101 | 102 | @Override 103 | public void onSpeakResumed() { 104 | //继续播放 105 | isPlaying = true; 106 | 107 | } 108 | }); 109 | } 110 | } 111 | break; 112 | case CHECK_TTS_PLAY: 113 | if (!isPlaying) { 114 | handler.obtainMessage(1).sendToTarget(); 115 | } 116 | break; 117 | } 118 | 119 | } 120 | }; 121 | 122 | private TTSController(Context context) { 123 | mContext = context.getApplicationContext(); 124 | SpeechUtility.createUtility(mContext, SpeechConstant.APPID + "=" + appId); 125 | if (mTts == null) { 126 | createSynthesizer(); 127 | } 128 | } 129 | 130 | private void createSynthesizer() { 131 | mTts = SpeechSynthesizer.createSynthesizer(mContext, 132 | new InitListener() { 133 | @Override 134 | public void onInit(int errorcode) { 135 | if (ErrorCode.SUCCESS == errorcode) { 136 | } else { 137 | Toast.makeText(mContext, "语音合成初始化失败!", Toast.LENGTH_SHORT); 138 | } 139 | } 140 | }); 141 | } 142 | 143 | public void init() { 144 | //设置发音人 145 | mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan"); //xiaoyan 支持年轻女声小燕,年轻男声小宇,中老年男声老孙,可爱蜡笔小新等声音 146 | //设置语速,值范围:[0, 100],默认值:50 147 | mTts.setParameter(SpeechConstant.SPEED, "55"); 148 | //设置音量 149 | mTts.setParameter(SpeechConstant.VOLUME, "tts_volume"); 150 | //设置语调 151 | mTts.setParameter(SpeechConstant.PITCH, "tts_pitch"); 152 | } 153 | 154 | public static TTSController getInstance(Context context) { 155 | if (ttsManager == null) { 156 | ttsManager = new TTSController(context); 157 | } 158 | return ttsManager; 159 | } 160 | 161 | public void stopSpeaking() { 162 | if (wordList != null) { 163 | wordList.clear(); 164 | } 165 | if (mTts != null) { 166 | mTts.stopSpeaking(); 167 | } 168 | isPlaying = false; 169 | } 170 | 171 | public void destroy() { 172 | if (wordList != null) { 173 | wordList.clear(); 174 | } 175 | if (mTts != null) { 176 | mTts.destroy(); 177 | } 178 | } 179 | 180 | /**************************************************************************** 181 | * 以下都是导航相关接口 182 | ****************************************************************************/ 183 | 184 | 185 | @Override 186 | public void onArriveDestination() { 187 | } 188 | 189 | @Override 190 | public void onArrivedWayPoint(int arg0) { 191 | } 192 | 193 | @Override 194 | public void onCalculateRouteFailure(int arg0) { 195 | if (wordList != null) 196 | wordList.addLast("路线规划失败"); 197 | } 198 | 199 | @Override 200 | public void onCalculateRouteSuccess() { 201 | } 202 | 203 | @Override 204 | public void onEndEmulatorNavi() { 205 | } 206 | 207 | @Override 208 | public void onGetNavigationText(int arg0, String arg1) { 209 | if (wordList != null) 210 | wordList.addLast(arg1); 211 | handler.obtainMessage(CHECK_TTS_PLAY).sendToTarget(); 212 | } 213 | 214 | 215 | @Override 216 | public void onInitNaviFailure() { 217 | } 218 | 219 | @Override 220 | public void onInitNaviSuccess() { 221 | } 222 | 223 | @Override 224 | public void onLocationChange(AMapNaviLocation arg0) { 225 | } 226 | 227 | @Override 228 | public void onReCalculateRouteForTrafficJam() { 229 | if (wordList != null) 230 | wordList.addLast("前方路线拥堵,路线重新规划"); 231 | } 232 | 233 | @Override 234 | public void onReCalculateRouteForYaw() { 235 | if (wordList != null) 236 | wordList.addLast("路线重新规划"); 237 | } 238 | 239 | @Override 240 | public void onStartNavi(int arg0) { 241 | } 242 | 243 | @Override 244 | public void onTrafficStatusUpdate() { 245 | } 246 | 247 | @Override 248 | public void onGpsOpenStatus(boolean enabled) { 249 | } 250 | 251 | @Override 252 | public void onNaviInfoUpdate(NaviInfo naviinfo) { 253 | 254 | } 255 | 256 | @Override 257 | public void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) { 258 | 259 | } 260 | 261 | @Override 262 | public void updateCameraInfo(AMapNaviCameraInfo[] infoArray) { 263 | 264 | } 265 | 266 | @Override 267 | public void onServiceAreaUpdate(AMapServiceAreaInfo[] infoArray) { 268 | 269 | } 270 | 271 | @Override 272 | public void showCross(AMapNaviCross aMapNaviCross) { 273 | 274 | } 275 | 276 | @Override 277 | public void hideCross() { 278 | 279 | } 280 | 281 | @Override 282 | public void showLaneInfo(AMapLaneInfo[] laneInfos, byte[] laneBackgroundInfo, byte[] laneRecommendedInfo) { 283 | 284 | } 285 | 286 | 287 | @Override 288 | public void hideLaneInfo() { 289 | 290 | } 291 | 292 | @Override 293 | public void onCalculateMultipleRoutesSuccess(int[] routeIds) { 294 | 295 | } 296 | 297 | @Override 298 | public void notifyParallelRoad(int parallelRoadType) { 299 | 300 | } 301 | 302 | @Override 303 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) { 304 | 305 | } 306 | 307 | @Override 308 | public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] infos) { 309 | 310 | } 311 | 312 | @Override 313 | public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) { 314 | 315 | } 316 | 317 | @Override 318 | public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) { 319 | 320 | } 321 | 322 | @Override 323 | public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) { 324 | 325 | } 326 | 327 | @Override 328 | public void onPlayRing(int type) { 329 | 330 | } 331 | 332 | 333 | @Override 334 | public void carProjectionChange(AmapCarLocation mCarProjectionChange) { 335 | 336 | } 337 | 338 | 339 | } 340 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/adapter/MapHistoryListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.test.map.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.TextView; 9 | 10 | import com.test.map.R; 11 | import com.test.map.sqlite.MapHistoryBean; 12 | import com.test.map.util.LogUtil; 13 | 14 | import java.util.List; 15 | 16 | 17 | /** 18 | * Created by FAN on 2017/5/11. 19 | */ 20 | public class MapHistoryListAdapter extends BaseAdapter { 21 | private List data; 22 | private LayoutInflater layoutInflater; 23 | private Context context; 24 | 25 | public MapHistoryListAdapter(Context context, List been) { 26 | this.context = context; 27 | this.data = been; 28 | this.layoutInflater = LayoutInflater.from(context); 29 | } 30 | 31 | @Override 32 | public int getCount() { 33 | return data.size(); 34 | } 35 | 36 | /** 37 | * 获得某一位置的数据 38 | */ 39 | @Override 40 | public Object getItem(int position) { 41 | return data.get(position); 42 | } 43 | 44 | /** 45 | * 获得唯一标识 46 | */ 47 | @Override 48 | public long getItemId(int position) { 49 | return position; 50 | } 51 | 52 | 53 | @Override 54 | public View getView(int position, View convertView, ViewGroup parent) { 55 | ViewHolder viewHolder = null; 56 | if (convertView == null) { 57 | viewHolder = new ViewHolder(); 58 | //获得组件,实例化组件 59 | convertView = layoutInflater.inflate(R.layout.map_history_list_item, null); 60 | viewHolder.mapHistory_Name = (TextView) convertView.findViewById(R.id.map_history_name); 61 | convertView.setTag(viewHolder); 62 | } else { 63 | viewHolder = (ViewHolder) convertView.getTag(); 64 | } 65 | //绑定数据 66 | if (null==data.get(position).getName()){ 67 | LogUtil.e("kong null"); 68 | }else { 69 | viewHolder.mapHistory_Name.setText(data.get(position).getName()); 70 | } 71 | 72 | 73 | return convertView; 74 | } 75 | 76 | public final class ViewHolder { 77 | public TextView mapHistory_Name; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/adapter/PoiSearchListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.test.map.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.TextView; 9 | 10 | import com.test.map.R; 11 | 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | 16 | /** 17 | * Created by FAN on 2017/5/11. 18 | */ 19 | public class PoiSearchListAdapter extends BaseAdapter { 20 | private List> data; 21 | private LayoutInflater layoutInflater; 22 | private Context context; 23 | 24 | public PoiSearchListAdapter(Context context, List> data) { 25 | this.context = context; 26 | this.data = data; 27 | this.layoutInflater = LayoutInflater.from(context); 28 | } 29 | 30 | @Override 31 | public int getCount() { 32 | return data.size(); 33 | } 34 | 35 | /** 36 | * 获得某一位置的数据 37 | */ 38 | @Override 39 | public Object getItem(int position) { 40 | return data.get(position); 41 | } 42 | 43 | /** 44 | * 获得唯一标识 45 | */ 46 | @Override 47 | public long getItemId(int position) { 48 | return position; 49 | } 50 | 51 | 52 | @Override 53 | public View getView(int position, View convertView, ViewGroup parent) { 54 | ViewHolder viewHolder = null; 55 | if (convertView == null) { 56 | viewHolder = new ViewHolder(); 57 | //获得组件,实例化组件 58 | convertView = layoutInflater.inflate(R.layout.map_list_item, null); 59 | viewHolder.map_Name = (TextView) convertView.findViewById(R.id.item_map_name); 60 | viewHolder.map_Address = (TextView) convertView.findViewById(R.id.item_map_address); 61 | viewHolder.map_distance = (TextView) convertView.findViewById(R.id.item_map_distance); 62 | convertView.setTag(viewHolder); 63 | } else { 64 | viewHolder = (ViewHolder) convertView.getTag(); 65 | } 66 | //绑定数据 67 | viewHolder.map_Name.setText((String) data.get(position).get("mapName")); 68 | viewHolder.map_Address.setText((String) data.get(position).get("mapAddress")); 69 | viewHolder.map_distance.setText((String) data.get(position).get("mapDistance")); 70 | 71 | return convertView; 72 | } 73 | 74 | public final class ViewHolder { 75 | public TextView map_Name; 76 | public TextView map_Address; 77 | public TextView map_distance; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/fragment/PoiInformationFragment.java: -------------------------------------------------------------------------------- 1 | package com.test.map.fragment; 2 | 3 | import android.app.Fragment; 4 | import android.graphics.Color; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Button; 11 | import android.widget.LinearLayout; 12 | import android.widget.TextView; 13 | 14 | import com.test.map.MapActivity; 15 | import com.test.map.R; 16 | import com.test.map.model.PathPlanDataBean; 17 | import com.test.map.model.PoiInfoBean; 18 | import com.test.map.util.MapUtil; 19 | 20 | import org.greenrobot.eventbus.EventBus; 21 | import org.greenrobot.eventbus.Subscribe; 22 | import org.greenrobot.eventbus.ThreadMode; 23 | 24 | /** 25 | * Created by FAN on 2017/5/8. 26 | */ 27 | 28 | public class PoiInformationFragment extends Fragment { 29 | private TextView poi_name; 30 | private TextView poi_address; 31 | private TextView poi_distance; 32 | private Button go_there_bt; 33 | private LinearLayout ly_info; 34 | private LinearLayout ly_choice_mode; 35 | private Button bt_start_nav; 36 | 37 | private Button bt_poi_01; 38 | private Button bt_poi_02; 39 | private Button bt_poi_03; 40 | private TextView tv_nav_time; 41 | private TextView tv_nav_distance; 42 | private TextView tv_nav_light; 43 | 44 | @Override 45 | public void onCreate(@Nullable Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | EventBus.getDefault().register(this); 48 | } 49 | 50 | @Nullable 51 | @Override 52 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 53 | View root = inflater.inflate(R.layout.fragment_poi_info, container, false); 54 | initUi(root); 55 | showPoiInfoLy(); 56 | hideChoiceLy(); 57 | return root; 58 | } 59 | 60 | private void initUi(View root) { 61 | ly_info = (LinearLayout) root.findViewById(R.id.ly_info); 62 | ly_choice_mode = (LinearLayout) root.findViewById(R.id.ly_choice_mode); 63 | 64 | poi_name = (TextView) root.findViewById(R.id.poi_name); 65 | poi_address = (TextView) root.findViewById(R.id.poi_address); 66 | poi_distance = (TextView) root.findViewById(R.id.poi_distance); 67 | go_there_bt = (Button) root.findViewById(R.id.go_there_bt); 68 | go_there_bt.setOnClickListener(new View.OnClickListener() { 69 | @Override 70 | public void onClick(View view) { 71 | EventBus.getDefault().post("默认"); 72 | hidePoiInfoLy(); 73 | showChoiceLy(); 74 | 75 | } 76 | }); 77 | bt_start_nav=(Button)root.findViewById(R.id.bt_start_nav); 78 | bt_start_nav.setOnClickListener(new View.OnClickListener() { 79 | @Override 80 | public void onClick(View v) { 81 | EventBus.getDefault().post("开始导航"); 82 | showPoiInfoLy(); 83 | hideChoiceLy(); 84 | } 85 | }); 86 | 87 | bt_poi_01 = (Button) root.findViewById(R.id.bt_poi_01); 88 | bt_poi_02 = (Button) root.findViewById(R.id.bt_poi_02); 89 | bt_poi_03 = (Button) root.findViewById(R.id.bt_poi_03); 90 | 91 | bt_poi_01.setOnClickListener(new View.OnClickListener() { 92 | @Override 93 | public void onClick(View view) { 94 | EventBus.getDefault().post("默认"); 95 | MapUtil.PathPlanningMode=0; 96 | changeUi(); 97 | } 98 | }); 99 | bt_poi_02.setOnClickListener(new View.OnClickListener() { 100 | @Override 101 | public void onClick(View view) { 102 | EventBus.getDefault().post("距离最短"); 103 | MapUtil.PathPlanningMode=1; 104 | changeUi(); 105 | } 106 | }); 107 | bt_poi_03.setOnClickListener(new View.OnClickListener() { 108 | @Override 109 | public void onClick(View view) { 110 | EventBus.getDefault().post("避免拥堵"); 111 | MapUtil.PathPlanningMode=2; 112 | changeUi(); 113 | } 114 | }); 115 | tv_nav_time=(TextView)root.findViewById(R.id.tv_nav_time); 116 | tv_nav_distance=(TextView)root.findViewById(R.id.tv_nav_distance); 117 | tv_nav_light=(TextView)root.findViewById(R.id.tv_nav_light); 118 | } 119 | 120 | /** 121 | * 显现 poi信息 122 | */ 123 | private void showPoiInfoLy() { 124 | ly_info.setVisibility(View.VISIBLE); 125 | } 126 | 127 | /** 128 | * 隐藏 poi信息 129 | */ 130 | private void hidePoiInfoLy() { 131 | ly_info.setVisibility(View.GONE); 132 | } 133 | 134 | /** 135 | * 显现 导航策略信息 136 | */ 137 | private void showChoiceLy() { 138 | ly_choice_mode.setVisibility(View.VISIBLE); 139 | } 140 | 141 | /** 142 | * 隐藏 导航策略信息 143 | */ 144 | private void hideChoiceLy() { 145 | ly_choice_mode.setVisibility(View.GONE); 146 | } 147 | 148 | /** 149 | * EventBus 接收 150 | */ 151 | 152 | @Subscribe(threadMode = ThreadMode.MAIN) 153 | public void onEvent(PoiInfoBean poiInfoBean) { 154 | String PoiName = poiInfoBean.getPoi_Name(); 155 | String PoiAddress = poiInfoBean.getPoi_Address(); 156 | String PoiDistance = poiInfoBean.getPoi_Distance(); 157 | poi_name.setText(PoiName); 158 | poi_address.setText(PoiAddress); 159 | poi_distance.setText("距离 "+PoiDistance + " 公里"); 160 | } 161 | 162 | @Subscribe(threadMode = ThreadMode.MAIN) 163 | public void onEvent(PathPlanDataBean pathPlanDataBean) { 164 | String time = pathPlanDataBean.getTime(); 165 | String distance = pathPlanDataBean.getDistance(); 166 | tv_nav_time.setText(time); 167 | tv_nav_distance.setText(distance); 168 | } 169 | 170 | @Subscribe(threadMode = ThreadMode.MAIN) 171 | public void onEvent(String string) { 172 | if (string.equalsIgnoreCase("查看poi信息界面是否在算路界面")) { 173 | if (MapActivity.TEXT_GO_MODE == 1) { 174 | showPoiInfoLy(); 175 | hideChoiceLy(); 176 | MapActivity.TEXT_GO_MODE = 0; 177 | go_there_bt.setText("去这里"); 178 | } 179 | }else if (string.contains("红绿灯")){ 180 | String light=string; 181 | tv_nav_light.setText(light); 182 | } 183 | } 184 | 185 | @Override 186 | public void onDestroy() { 187 | super.onDestroy(); 188 | EventBus.getDefault().unregister(this); 189 | } 190 | 191 | private void changeUi(){ 192 | if (MapUtil.PathPlanningMode==0){ 193 | bt_poi_01.setTextColor(Color.parseColor("#FFFFFF")); 194 | bt_poi_01.setBackground(getActivity().getResources().getDrawable(R.drawable.map_bt_bottm_bg_l)); 195 | bt_poi_02.setTextColor(Color.parseColor("#9a9b98")); 196 | bt_poi_02.setBackground(getActivity().getResources().getDrawable(R.drawable.map_bt_bottm_bg_w)); 197 | bt_poi_03.setTextColor(Color.parseColor("#9a9b98")); 198 | bt_poi_03.setBackground(getActivity().getResources().getDrawable(R.drawable.map_bt_bottm_bg_w)); 199 | }else if (MapUtil.PathPlanningMode==1){ 200 | bt_poi_01.setTextColor(Color.parseColor("#9a9b98")); 201 | bt_poi_01.setBackground(getActivity().getResources().getDrawable(R.drawable.map_bt_bottm_bg_w)); 202 | bt_poi_02.setTextColor(Color.parseColor("#FFFFFF")); 203 | bt_poi_02.setBackground(getActivity().getResources().getDrawable(R.drawable.map_bt_bottm_bg_l)); 204 | bt_poi_03.setTextColor(Color.parseColor("#9a9b98")); 205 | bt_poi_03.setBackground(getActivity().getResources().getDrawable(R.drawable.map_bt_bottm_bg_w)); 206 | }else if (MapUtil.PathPlanningMode==2){ 207 | bt_poi_01.setTextColor(Color.parseColor("#9a9b98")); 208 | bt_poi_01.setBackground(getActivity().getResources().getDrawable(R.drawable.map_bt_bottm_bg_w)); 209 | bt_poi_02.setTextColor(Color.parseColor("#9a9b98")); 210 | bt_poi_02.setBackground(getActivity().getResources().getDrawable(R.drawable.map_bt_bottm_bg_w)); 211 | bt_poi_03.setTextColor(Color.parseColor("#FFFFFF")); 212 | bt_poi_03.setBackground(getActivity().getResources().getDrawable(R.drawable.map_bt_bottm_bg_l)); 213 | } 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/fragment/PoiSearchPageFragment.java: -------------------------------------------------------------------------------- 1 | package com.test.map.fragment; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.text.Editable; 7 | import android.text.TextWatcher; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.AdapterView; 12 | import android.widget.AutoCompleteTextView; 13 | import android.widget.ImageView; 14 | import android.widget.ListView; 15 | import android.widget.RelativeLayout; 16 | import android.widget.TextView; 17 | import android.widget.Toast; 18 | 19 | import com.amap.api.maps.model.LatLng; 20 | import com.amap.api.services.core.LatLonPoint; 21 | import com.amap.api.services.help.Inputtips; 22 | import com.amap.api.services.help.InputtipsQuery; 23 | import com.amap.api.services.help.Tip; 24 | import com.test.map.MapActivity; 25 | import com.test.map.R; 26 | import com.test.map.adapter.MapHistoryListAdapter; 27 | import com.test.map.adapter.PoiSearchListAdapter; 28 | import com.test.map.model.PoiItemOnclickBean; 29 | import com.test.map.sqlite.MapHistoryBean; 30 | import com.test.map.util.LogUtil; 31 | import com.test.map.util.MapUtil; 32 | 33 | import org.greenrobot.eventbus.EventBus; 34 | import org.greenrobot.eventbus.Subscribe; 35 | import org.greenrobot.eventbus.ThreadMode; 36 | 37 | import java.util.ArrayList; 38 | import java.util.HashMap; 39 | import java.util.List; 40 | import java.util.Map; 41 | 42 | /** 43 | * Created by FAN on 2017/5/9. 44 | */ 45 | 46 | public class PoiSearchPageFragment extends Fragment { 47 | private AutoCompleteTextView autoCompleteTextView; 48 | private ImageView back_map; 49 | private ListView list_input; 50 | private RelativeLayout ly_history_page; 51 | private ListView list_history; 52 | private TextView map_clear_history; 53 | private TextView map_null_history; 54 | private TextWatch textWatch; 55 | private InputLisenerTest inputLisenerTest; 56 | List> listItem; //输入keyword,数据返回的list数据源 57 | 58 | @Override 59 | public void onCreate(@Nullable Bundle savedInstanceState) { 60 | super.onCreate(savedInstanceState); 61 | EventBus.getDefault().register(this); 62 | } 63 | 64 | @Nullable 65 | @Override 66 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 67 | View root = inflater.inflate(R.layout.fragment_poi_search, container, false); 68 | initUi(root); 69 | return root; 70 | } 71 | 72 | 73 | private void initUi(View root) { 74 | autoCompleteTextView = (AutoCompleteTextView) root.findViewById(R.id.keyWord); 75 | back_map = (ImageView) root.findViewById(R.id.back_map); 76 | list_input = (ListView) root.findViewById(R.id.list_input); 77 | textWatch = new TextWatch(); 78 | inputLisenerTest = new InputLisenerTest(); 79 | autoCompleteTextView.addTextChangedListener(textWatch); 80 | back_map.setOnClickListener(new View.OnClickListener() { 81 | @Override 82 | public void onClick(View view) { 83 | EventBus.getDefault().post("back_map"); 84 | } 85 | }); 86 | ly_history_page=(RelativeLayout) root.findViewById(R.id.ly_history_page); 87 | list_history=(ListView)root.findViewById(R.id.list_history); 88 | map_clear_history=(TextView)root.findViewById(R.id.map_clear_history); 89 | map_null_history=(TextView)root.findViewById(R.id.map_null_history); 90 | if (null==MapActivity.mapHistoryBeenList||MapActivity.mapHistoryBeenList.size()<1){ 91 | showHistoryText(); 92 | hideHistoryPage(); 93 | } 94 | if (null==MapActivity.mapHistoryBeenList||MapActivity.mapHistoryBeenList.size()<1) 95 | return; 96 | list_history.setAdapter(new MapHistoryListAdapter(getActivity(),MapActivity.mapHistoryBeenList)); 97 | list_history.setOnItemClickListener(new AdapterView.OnItemClickListener() { 98 | @Override 99 | public void onItemClick(AdapterView parent, View view, int position, long id) { 100 | String name= MapActivity.mapHistoryBeenList.get(position).getName(); 101 | String address= MapActivity.mapHistoryBeenList.get(position).getAddress(); 102 | String distance= MapActivity.mapHistoryBeenList.get(position).getDistance(); 103 | String dd= MapActivity.mapHistoryBeenList.get(position).getLat(); 104 | String ss= MapActivity.mapHistoryBeenList.get(position).getLon(); 105 | LatLonPoint mlatLonPointItem=new LatLonPoint(Double.valueOf(dd),Double.valueOf(ss)); 106 | 107 | PoiItemOnclickBean poiItemOnclickBean = new PoiItemOnclickBean(name, address, distance, mlatLonPointItem); 108 | EventBus.getDefault().post(poiItemOnclickBean); 109 | } 110 | }); 111 | 112 | map_clear_history.setOnClickListener(new View.OnClickListener() { 113 | @Override 114 | public void onClick(View v) { 115 | EventBus.getDefault().post("ClearMapHistory"); 116 | } 117 | }); 118 | 119 | } 120 | /** 121 | * 显现 input listview 122 | */ 123 | private void showInputListView(){ 124 | list_input.setVisibility(View.VISIBLE); 125 | } 126 | /** 127 | * 隐藏input listview 128 | */ 129 | private void hideInputListView(){ 130 | list_input.setVisibility(View.GONE); 131 | } 132 | /** 133 | * 显现 历史记录 134 | */ 135 | private void showHistoryPage(){ 136 | ly_history_page.setVisibility(View.VISIBLE); 137 | } 138 | /** 139 | * 隐藏历史记录 140 | */ 141 | private void hideHistoryPage(){ 142 | ly_history_page.setVisibility(View.GONE); 143 | } 144 | /** 145 | * 显现 无历史记录 TEXT 146 | */ 147 | private void showHistoryText(){ 148 | map_null_history.setVisibility(View.VISIBLE); 149 | } 150 | /** 151 | * 隐藏无历史记录 TEXT 152 | */ 153 | private void hideHistoryText(){ 154 | map_null_history.setVisibility(View.GONE); 155 | } 156 | 157 | class TextWatch implements TextWatcher { 158 | @Override 159 | public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { 160 | } 161 | @Override 162 | public void onTextChanged(CharSequence s, int start, int stop, int count) { 163 | String newText = s.toString().trim(); 164 | if(s.length()<1){ 165 | showHistoryPage(); 166 | hideHistoryText(); 167 | hideInputListView(); 168 | }else { 169 | showInputListView(); 170 | hideHistoryText(); 171 | hideHistoryPage(); 172 | } 173 | if (!MapUtil.IsEmptyOrNullString(newText)) { 174 | InputtipsQuery inputquery = new InputtipsQuery(newText, MapUtil.LOCATION_CITY); 175 | Inputtips inputTips = new Inputtips(getActivity(), inputquery); 176 | inputTips.setInputtipsListener(inputLisenerTest); //设置=======得到数据监听======= 177 | inputTips.requestInputtipsAsyn(); 178 | } 179 | } 180 | @Override 181 | public void afterTextChanged(Editable editable) { 182 | } 183 | } 184 | class InputLisenerTest implements Inputtips.InputtipsListener { 185 | 186 | @Override 187 | public void onGetInputtips(List tipList, int rCode) { 188 | if (rCode == 1000) {// 正确返回 189 | boolean ee = tipList.size() > 0; 190 | LogUtil.e("=======数据监听正确返回" + tipList.toString() + ee); 191 | listItem = new ArrayList>(); 192 | for (int i = 0; i < tipList.size(); i++) { 193 | if (tipList.get(i).getPoint() != null) { 194 | LatLng startLatLng = MapUtil.latLon; //转化LatLng单位 195 | LatLonPoint latLonPoint = tipList.get(i).getPoint(); //得到要去的地方的坐标经纬度 196 | LatLng stopLatLng = MapUtil.convertToLatLng(latLonPoint); //转化LatLng单位 197 | String kmDistance = MapUtil.distanceLatLng(startLatLng, stopLatLng); 198 | HashMap map = new HashMap(); 199 | map.put("mapName", tipList.get(i).getName()); 200 | map.put("mapAddress", tipList.get(i).getDistrict()); 201 | map.put("mapPosition", tipList.get(i).getPoint()); 202 | map.put("mapDistance", kmDistance); 203 | listItem.add(map); 204 | LogUtil.e("名称:" + tipList.get(i).getName() + "地点:" + tipList.get(i).getDistrict() + "经纬度:" + tipList.get(i).getPoint() + "距离:" + kmDistance + "km"); 205 | } 206 | } 207 | list_input.setAdapter(new PoiSearchListAdapter(getActivity(), listItem)); 208 | list_input.setOnItemClickListener(new AdapterView.OnItemClickListener() { 209 | @Override 210 | public void onItemClick(AdapterView adapterView, View view, int i, long l) { 211 | String poiName = (String) listItem.get(i).get("mapName"); //地名 212 | String poiAddress = (String) listItem.get(i).get("mapAddress"); //地址 213 | String poiDistance = (String) listItem.get(i).get("mapDistance"); //距离 214 | LatLonPoint poiLatLonPoint = (LatLonPoint) (listItem.get(i).get("mapPosition")); //经纬度 215 | 216 | PoiItemOnclickBean poiItemOnclickBean = new PoiItemOnclickBean(poiName, poiAddress, poiDistance, poiLatLonPoint); 217 | EventBus.getDefault().post(poiItemOnclickBean); 218 | 219 | String mapHistoryLat=poiLatLonPoint.getLatitude()+""; 220 | String mapHistoryLon=poiLatLonPoint.getLongitude()+""; 221 | 222 | MapHistoryBean mapHistoryBean=new MapHistoryBean(); 223 | mapHistoryBean.setName(poiName); 224 | mapHistoryBean.setAddress(poiAddress); 225 | mapHistoryBean.setDistance(poiDistance); 226 | mapHistoryBean.setLat(mapHistoryLat); 227 | mapHistoryBean.setLon(mapHistoryLon); 228 | EventBus.getDefault().post(mapHistoryBean); 229 | 230 | autoCompleteTextView.setText(""); 231 | } 232 | }); 233 | } else { 234 | rCodeGaoDe(rCode); 235 | } 236 | } 237 | } 238 | 239 | private void rCodeGaoDe(int rCode) { 240 | switch (rCode) { 241 | case 1802: 242 | case 1804: 243 | case 1806: 244 | Toast.makeText(getActivity(), "连接超时,请检查网络状况是否良好", Toast.LENGTH_SHORT).show(); 245 | break; 246 | case 3000: 247 | Toast.makeText(getActivity(), "不在中国范围内", Toast.LENGTH_SHORT).show(); 248 | break; 249 | case 3001: 250 | Toast.makeText(getActivity(), "附近搜索不道路", Toast.LENGTH_SHORT).show(); 251 | break; 252 | case 3002: 253 | Toast.makeText(getActivity(), "路线计算失败", Toast.LENGTH_SHORT).show(); 254 | break; 255 | case 3003: 256 | Toast.makeText(getActivity(), "起点、终点距离过长导致算路失败", Toast.LENGTH_SHORT).show(); 257 | break; 258 | } 259 | } 260 | 261 | 262 | @Override 263 | public void onDestroy() { 264 | super.onDestroy(); 265 | EventBus.getDefault().unregister(this); 266 | } 267 | 268 | /** 269 | * EventBus 接收 270 | */ 271 | 272 | @Subscribe(threadMode = ThreadMode.MAIN) 273 | public void onEvent(String msg) { 274 | if (msg.equalsIgnoreCase("HistoryNull")){ 275 | if (null==MapActivity.mapHistoryBeenList||MapActivity.mapHistoryBeenList.size()<1){ 276 | showHistoryText(); 277 | hideHistoryPage(); 278 | } 279 | } 280 | } 281 | 282 | 283 | } 284 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/listener/GeocodeSearchListenerUtil.java: -------------------------------------------------------------------------------- 1 | package com.test.map.listener; 2 | 3 | import android.content.Context; 4 | 5 | import com.amap.api.services.core.AMapException; 6 | import com.amap.api.services.geocoder.GeocodeResult; 7 | import com.amap.api.services.geocoder.GeocodeSearch; 8 | import com.amap.api.services.geocoder.RegeocodeResult; 9 | import com.test.map.MapActivity; 10 | import com.test.map.model.PoiInfoBean; 11 | import com.test.map.util.LogUtil; 12 | import com.test.map.util.MapUtil; 13 | 14 | import org.greenrobot.eventbus.EventBus; 15 | 16 | /** 17 | * Created by FAN on 2017/5/8. 18 | */ 19 | 20 | public class GeocodeSearchListenerUtil implements GeocodeSearch.OnGeocodeSearchListener { 21 | public static GeocodeSearch geocoderSearch; 22 | private Context context; 23 | public GeocodeSearchListenerUtil(Context context){ 24 | this.context=context; 25 | geocoderSearch = new GeocodeSearch(context); 26 | geocoderSearch.setOnGeocodeSearchListener(this); 27 | } 28 | @Override 29 | public void onRegeocodeSearched(RegeocodeResult result, int rCode) { 30 | if (rCode == AMapException.CODE_AMAP_SUCCESS) { 31 | if (result != null && result.getRegeocodeAddress() != null 32 | && result.getRegeocodeAddress().getFormatAddress() != null) { 33 | String addressName = result.getRegeocodeAddress().getFormatAddress(); 34 | String distance= MapUtil.distanceLatLng(MapUtil.latLon, MapActivity.poiLatLng); 35 | LogUtil.e(""+addressName+"距离:"+distance); 36 | PoiInfoBean poiInfoBean=new PoiInfoBean(MapActivity.infoPoiName, addressName,distance,MapActivity.mLatLonPoint); 37 | EventBus.getDefault().post(poiInfoBean); 38 | } else { 39 | LogUtil.e("onRegeocodeSearched 无返回结果"); 40 | } 41 | } else { 42 | LogUtil.e("onRegeocodeSearched 错误码:"+rCode); 43 | } 44 | } 45 | 46 | @Override 47 | public void onGeocodeSearched(GeocodeResult geocodeResult, int i) { 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/listener/MyLocationChangeListenerUtil.java: -------------------------------------------------------------------------------- 1 | package com.test.map.listener; 2 | 3 | import android.content.Context; 4 | import android.location.Location; 5 | 6 | import com.amap.api.maps.AMap; 7 | import com.test.map.util.LogUtil; 8 | import com.test.map.util.MapUtil; 9 | 10 | /** 11 | * Created by FAN on 2017/5/8. 12 | */ 13 | 14 | public class MyLocationChangeListenerUtil implements AMap.OnMyLocationChangeListener { 15 | public static MyLocationChangeListenerUtil myLocationChangeListenerUtil; 16 | private Context context; 17 | 18 | public MyLocationChangeListenerUtil(Context context) { 19 | this.context = context; 20 | } 21 | 22 | public static MyLocationChangeListenerUtil getInstance(Context context) { 23 | if (myLocationChangeListenerUtil == null) { 24 | myLocationChangeListenerUtil = new MyLocationChangeListenerUtil(context); 25 | } 26 | return myLocationChangeListenerUtil; 27 | } 28 | 29 | @Override 30 | public void onMyLocationChange(Location location) { 31 | if (location != null) { 32 | MapUtil.latLon = MapUtil.getLatLng(location); 33 | if (MapUtil.latLon != null) { 34 | MapUtil.latLonPoint = MapUtil.convertToLatLonPoint(MapUtil.latLon); 35 | } 36 | // MapActivity.poiLatLng= MapUtil.latLon; 37 | LogUtil.e("amap onMyLocationChange 定位成功, lat: " + location.getLatitude() + " lon: " + location.getLongitude()); 38 | } else { 39 | LogUtil.e("amap 定位失败"); 40 | } 41 | } 42 | 43 | /** 44 | * 以下内容为 onMyLocationChange 里填写,暂时不用 45 | * Bundle bundle = location.getExtras(); 46 | if(bundle != null) { 47 | int errorCode = bundle.getInt(MyLocationStyle.ERROR_CODE); 48 | String errorInfo = bundle.getString(MyLocationStyle.ERROR_INFO); 49 | // 定位类型,可能为GPS WIFI等,具体可以参考官网的定位SDK介绍 50 | int locationType = bundle.getInt(MyLocationStyle.LOCATION_TYPE); 51 | Log.e("amap", "定位信息, code: " + errorCode + " errorInfo: " + errorInfo + " locationType: " + locationType ); 52 | } else { 53 | Log.e("amap", "定位信息, bundle is null "); 54 | } 55 | */ 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/model/NaviLatLngBean.java: -------------------------------------------------------------------------------- 1 | package com.test.map.model; 2 | 3 | import com.amap.api.navi.model.NaviLatLng; 4 | 5 | /** 6 | * Created by FAN on 2017/5/11. 7 | */ 8 | 9 | public class NaviLatLngBean { 10 | /** 11 | * 导航起始坐标 12 | */ 13 | private NaviLatLng startNaviLatLng; 14 | /** 15 | * 导航终点坐标 16 | */ 17 | private NaviLatLng stopNaviLatLng; 18 | 19 | public NaviLatLngBean(NaviLatLng startNaviLatLng, NaviLatLng stopNaviLatLng) { 20 | this.startNaviLatLng = startNaviLatLng; 21 | this.stopNaviLatLng = stopNaviLatLng; 22 | } 23 | public NaviLatLng getStartNaviLatLng() { 24 | return startNaviLatLng; 25 | } 26 | 27 | public NaviLatLng getStopNaviLatLng() { 28 | return stopNaviLatLng; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return "NaviLatLngBean{" + 34 | "startNaviLatLng=" + startNaviLatLng + 35 | ", stopNaviLatLng=" + stopNaviLatLng + 36 | '}'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/model/PathPlanDataBean.java: -------------------------------------------------------------------------------- 1 | package com.test.map.model; 2 | 3 | /** 4 | * Created by FAN on 2017/5/11. 5 | */ 6 | 7 | public class PathPlanDataBean { 8 | private String Time; 9 | private String distance; 10 | 11 | public PathPlanDataBean(String time, String distance) { 12 | Time = time; 13 | this.distance = distance; 14 | } 15 | 16 | public String getTime() { 17 | return Time; 18 | } 19 | 20 | public String getDistance() { 21 | return distance; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "PathPlanDataBean{" + 27 | "Time='" + Time + '\'' + 28 | ", distance='" + distance + '\'' + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/model/PoiInfoBean.java: -------------------------------------------------------------------------------- 1 | package com.test.map.model; 2 | 3 | import com.amap.api.services.core.LatLonPoint; 4 | 5 | /** 6 | * Created by FAN on 2017/5/10. 7 | */ 8 | 9 | public class PoiInfoBean { 10 | 11 | 12 | /** 13 | * 地名 14 | */ 15 | private String Poi_Name; 16 | /** 17 | * 详细地址 18 | */ 19 | private String Poi_Address; 20 | 21 | /** 22 | * 与现在所处位置的距离 23 | */ 24 | private String Poi_Distance; 25 | /** 26 | * 经纬度 27 | */ 28 | private LatLonPoint latLonPoint; 29 | 30 | public PoiInfoBean(String poi_Name, String poi_Address, String poi_Distance, LatLonPoint latLonPoint) { 31 | Poi_Name = poi_Name; 32 | Poi_Address = poi_Address; 33 | Poi_Distance = poi_Distance; 34 | this.latLonPoint = latLonPoint; 35 | } 36 | public String getPoi_Name() { 37 | return Poi_Name; 38 | } 39 | 40 | public String getPoi_Address() { 41 | return Poi_Address; 42 | } 43 | 44 | public String getPoi_Distance() { 45 | return Poi_Distance; 46 | } 47 | 48 | public LatLonPoint getLatLonPoint() { 49 | return latLonPoint; 50 | } 51 | @Override 52 | public String toString() { 53 | return "PoiItemOnclickBean{" + 54 | "Poi_Name='" + Poi_Name + '\'' + 55 | ", Poi_Address='" + Poi_Address + '\'' + 56 | ", Poi_Distance='" + Poi_Distance + '\'' + 57 | ", latLonPoint=" + latLonPoint + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/model/PoiItemOnclickBean.java: -------------------------------------------------------------------------------- 1 | package com.test.map.model; 2 | 3 | import com.amap.api.services.core.LatLonPoint; 4 | 5 | /** 6 | * Created by FAN on 2017/5/10. 7 | */ 8 | 9 | public class PoiItemOnclickBean { 10 | 11 | 12 | /** 13 | * 地名 14 | */ 15 | private String Poi_Name; 16 | /** 17 | * 详细地址 18 | */ 19 | private String Poi_Address; 20 | 21 | /** 22 | * 与现在所处位置的距离 23 | */ 24 | private String Poi_Distance; 25 | /** 26 | * 经纬度 27 | */ 28 | private LatLonPoint latLonPoint; 29 | 30 | public PoiItemOnclickBean(String poi_Name, String poi_Address, String poi_Distance, LatLonPoint latLonPoint) { 31 | Poi_Name = poi_Name; 32 | Poi_Address = poi_Address; 33 | Poi_Distance = poi_Distance; 34 | this.latLonPoint = latLonPoint; 35 | } 36 | public String getPoi_Name() { 37 | return Poi_Name; 38 | } 39 | 40 | public String getPoi_Address() { 41 | return Poi_Address; 42 | } 43 | 44 | public String getPoi_Distance() { 45 | return Poi_Distance; 46 | } 47 | 48 | public LatLonPoint getLatLonPoint() { 49 | return latLonPoint; 50 | } 51 | @Override 52 | public String toString() { 53 | return "PoiItemOnclickBean{" + 54 | "Poi_Name='" + Poi_Name + '\'' + 55 | ", Poi_Address='" + Poi_Address + '\'' + 56 | ", Poi_Distance='" + Poi_Distance + '\'' + 57 | ", latLonPoint=" + latLonPoint + 58 | '}'; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/permission/BaseMPermission.java: -------------------------------------------------------------------------------- 1 | package com.test.map.permission; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Activity; 5 | import android.content.pm.PackageManager; 6 | import android.os.Build; 7 | import android.support.v4.app.Fragment; 8 | import android.util.Log; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class BaseMPermission { 14 | 15 | private static final String TAG = "MPermission"; 16 | 17 | public enum MPermissionResultEnum { 18 | GRANTED, DENIED, DENIED_NEVER_ASK_AGAIN 19 | } 20 | 21 | static boolean isOverMarshmallow() { 22 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; 23 | } 24 | 25 | static Activity getActivity(Object object) { 26 | if (object instanceof Fragment) { 27 | return ((Fragment) object).getActivity(); 28 | } else if (object instanceof Activity) { 29 | return (Activity) object; 30 | } 31 | return null; 32 | } 33 | 34 | /** 35 | * 获取权限请求结果 36 | */ 37 | public static List getPermissionResult(Activity activity, String[] permissions) { 38 | return findPermissionResult(activity, permissions); 39 | } 40 | 41 | public static List getPermissionResult(Fragment fragment, String[] permissions) { 42 | return findPermissionResult(fragment.getActivity(), permissions); 43 | } 44 | 45 | @TargetApi(value = Build.VERSION_CODES.M) 46 | private static List findPermissionResult(Activity activity, String... permissions) { 47 | boolean overM = isOverMarshmallow(); 48 | List result = new ArrayList<>(); 49 | for (String p : permissions) { 50 | if (overM) { 51 | if (activity.checkSelfPermission(p) == PackageManager.PERMISSION_GRANTED) { 52 | result.add(MPermissionResultEnum.GRANTED); 53 | } else { 54 | if (!activity.shouldShowRequestPermissionRationale(p)) { 55 | result.add(MPermissionResultEnum.DENIED_NEVER_ASK_AGAIN); 56 | } else { 57 | result.add(MPermissionResultEnum.DENIED); 58 | } 59 | } 60 | } else { 61 | result.add(MPermissionResultEnum.GRANTED); 62 | } 63 | } 64 | 65 | return result; 66 | } 67 | 68 | /** 69 | * 获取所有被未被授权的权限 70 | */ 71 | public static List getDeniedPermissions(Activity activity, String[] permissions) { 72 | return findDeniedPermissions(activity, permissions); 73 | } 74 | 75 | public static List getDeniedPermissions(Fragment fragment, String[] permissions) { 76 | return findDeniedPermissions(fragment.getActivity(), permissions); 77 | } 78 | 79 | @TargetApi(value = Build.VERSION_CODES.M) 80 | static List findDeniedPermissions(Activity activity, String... permissions) { 81 | if (!isOverMarshmallow()) { 82 | return null; 83 | } 84 | 85 | List denyPermissions = new ArrayList<>(); 86 | for (String value : permissions) { 87 | if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) { 88 | denyPermissions.add(value); 89 | } 90 | } 91 | return denyPermissions; 92 | } 93 | 94 | /** 95 | * 获取被拒绝且勾选不再询问的权限 96 | * 请在请求权限结果回调中使用,因为从未请求过的权限也会被认为是该结果集 97 | */ 98 | public static List getNeverAskAgainPermissions(Activity activity, String[] permissions) { 99 | return findNeverAskAgainPermissions(activity, permissions); 100 | } 101 | 102 | public static List getNeverAskAgainPermissions(Fragment fragment, String[] permissions) { 103 | return findNeverAskAgainPermissions(fragment.getActivity(), permissions); 104 | } 105 | 106 | @TargetApi(value = Build.VERSION_CODES.M) 107 | private static List findNeverAskAgainPermissions(Activity activity, String... permissions) { 108 | if (!isOverMarshmallow()) { 109 | return null; 110 | } 111 | 112 | List neverAskAgainPermission = new ArrayList<>(); 113 | for (String value : permissions) { 114 | if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED && 115 | !activity.shouldShowRequestPermissionRationale(value)) { 116 | // 拒绝&不要需要解释了(用户勾选了不再询问) 117 | // 坑爹:第一次不做任何设置,返回值也是false。建议在权限授权结果里判断!!! 118 | neverAskAgainPermission.add(value); 119 | } 120 | } 121 | 122 | return neverAskAgainPermission; 123 | } 124 | 125 | @TargetApi(value = Build.VERSION_CODES.M) 126 | static boolean hasNeverAskAgainPermission(Activity activity, List permission) { 127 | if (!isOverMarshmallow()) { 128 | return false; 129 | } 130 | 131 | for (String value : permission) { 132 | if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED && 133 | !activity.shouldShowRequestPermissionRationale(value)) { 134 | return true; 135 | } 136 | } 137 | 138 | return false; 139 | } 140 | 141 | /** 142 | * 获取被拒绝但没有勾选不再询问的权限(可以继续申请,会继续弹框) 143 | */ 144 | public static List getDeniedPermissionsWithoutNeverAskAgain(Activity activity, String[] permissions) { 145 | return findDeniedPermissionWithoutNeverAskAgain(activity, permissions); 146 | } 147 | 148 | public static List getDeniedPermissionsWithoutNeverAskAgain(Fragment fragment, String[] permissions) { 149 | return findDeniedPermissionWithoutNeverAskAgain(fragment.getActivity(), permissions); 150 | } 151 | 152 | @TargetApi(value = Build.VERSION_CODES.M) 153 | private static List findDeniedPermissionWithoutNeverAskAgain(Activity activity, String... permission) { 154 | if (!isOverMarshmallow()) { 155 | return null; 156 | } 157 | 158 | List denyPermissions = new ArrayList<>(); 159 | for (String value : permission) { 160 | if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED && 161 | activity.shouldShowRequestPermissionRationale(value)) { 162 | denyPermissions.add(value); // 上次申请被用户拒绝了 163 | } 164 | } 165 | 166 | return denyPermissions; 167 | } 168 | 169 | /** 170 | * Log专用 171 | */ 172 | public static void printMPermissionResult(boolean preRequest, Activity activity, String[] permissions) { 173 | Log.i(TAG, "----- MPermission result " + (preRequest ? "before" : "after") + " request:"); 174 | List result = MPermission.getPermissionResult(activity, permissions); 175 | int i = 0; 176 | for (BaseMPermission.MPermissionResultEnum p : result) { 177 | Log.i(TAG, "* MPermission=" + permissions[i++] + ", result=" + p); 178 | } 179 | } 180 | 181 | static String toString(List permission) { 182 | if (permission == null || permission.isEmpty()) { 183 | return ""; 184 | } 185 | 186 | return toString(permission.toArray(new String[permission.size()])); 187 | } 188 | 189 | private static String toString(String[] permission) { 190 | if (permission == null || permission.length <= 0) { 191 | return ""; 192 | } 193 | 194 | StringBuilder sb = new StringBuilder(); 195 | for (String p : permission) { 196 | sb.append(p.replaceFirst("android.permission.", "")); 197 | sb.append(","); 198 | } 199 | 200 | sb.deleteCharAt(sb.length() - 1); 201 | 202 | return sb.toString(); 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/permission/MPermission.java: -------------------------------------------------------------------------------- 1 | package com.test.map.permission; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Activity; 5 | import android.content.pm.PackageManager; 6 | import android.os.Build; 7 | import android.support.annotation.NonNull; 8 | import android.support.v4.app.Fragment; 9 | 10 | import com.test.map.permission.annotation.OnMPermissionDenied; 11 | import com.test.map.permission.annotation.OnMPermissionGranted; 12 | import com.test.map.permission.annotation.OnMPermissionNeverAskAgain; 13 | 14 | import java.lang.annotation.Annotation; 15 | import java.lang.reflect.InvocationTargetException; 16 | import java.lang.reflect.Method; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | 21 | public class MPermission extends BaseMPermission { 22 | 23 | private int requestCode; 24 | private String[] permissions; 25 | private Object object; // activity or fragment 26 | 27 | private MPermission(Object object) { 28 | this.object = object; 29 | } 30 | 31 | public static MPermission with(Activity activity) { 32 | return new MPermission(activity); 33 | } 34 | 35 | public static MPermission with(Fragment fragment) { 36 | return new MPermission(fragment); 37 | } 38 | 39 | public MPermission setRequestCode(int requestCode) { 40 | this.requestCode = requestCode; 41 | return this; 42 | } 43 | 44 | public MPermission permissions(String... permissions) { 45 | this.permissions = permissions; 46 | return this; 47 | } 48 | 49 | /** 50 | * ********************* request ********************* 51 | */ 52 | 53 | @TargetApi(value = Build.VERSION_CODES.M) 54 | public void request() { 55 | doRequestPermissions(object, requestCode, permissions); 56 | } 57 | 58 | @TargetApi(value = Build.VERSION_CODES.M) 59 | private static void doRequestPermissions(Object object, int requestCode, String[] permissions) { 60 | if (!isOverMarshmallow()) { 61 | doExecuteSuccess(object, requestCode); 62 | return; 63 | } 64 | 65 | List deniedPermissions = findDeniedPermissions(getActivity(object), permissions); 66 | if (deniedPermissions != null && deniedPermissions.size() > 0) { 67 | if (object instanceof Activity) { 68 | ((Activity) object).requestPermissions(deniedPermissions.toArray(new String[deniedPermissions.size()]), requestCode); 69 | } else if (object instanceof Fragment) { 70 | ((Fragment) object).requestPermissions(deniedPermissions.toArray(new String[deniedPermissions.size()]), requestCode); 71 | } else { 72 | throw new IllegalArgumentException(object.getClass().getName() + " is not supported"); 73 | } 74 | } else { 75 | doExecuteSuccess(object, requestCode); 76 | } 77 | } 78 | 79 | /** 80 | * ********************* on result ********************* 81 | */ 82 | 83 | public static void onRequestPermissionsResult(Activity activity, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 84 | dispatchResult(activity, requestCode, permissions, grantResults); 85 | } 86 | 87 | public static void onRequestPermissionsResult(Fragment fragment, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 88 | dispatchResult(fragment, requestCode, permissions, grantResults); 89 | } 90 | 91 | private static void dispatchResult(Object obj, int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 92 | List deniedPermissions = new ArrayList<>(); 93 | for (int i = 0; i < grantResults.length; i++) { 94 | if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { 95 | deniedPermissions.add(permissions[i]); 96 | } 97 | } 98 | 99 | if (deniedPermissions.size() > 0) { 100 | if (hasNeverAskAgainPermission(getActivity(obj), deniedPermissions)) { 101 | doExecuteFailAsNeverAskAgain(obj, requestCode); 102 | } else { 103 | doExecuteFail(obj, requestCode); 104 | } 105 | } else { 106 | doExecuteSuccess(obj, requestCode); 107 | } 108 | } 109 | 110 | /** 111 | * ********************* reflect execute result ********************* 112 | */ 113 | 114 | private static void doExecuteSuccess(Object activity, int requestCode) { 115 | executeMethod(activity, findMethodWithRequestCode(activity.getClass(), OnMPermissionGranted.class, requestCode)); 116 | } 117 | 118 | private static void doExecuteFail(Object activity, int requestCode) { 119 | executeMethod(activity, findMethodWithRequestCode(activity.getClass(), OnMPermissionDenied.class, requestCode)); 120 | } 121 | 122 | private static void doExecuteFailAsNeverAskAgain(Object activity, int requestCode) { 123 | executeMethod(activity, findMethodWithRequestCode(activity.getClass(), OnMPermissionNeverAskAgain.class, requestCode)); 124 | } 125 | 126 | private static Method findMethodWithRequestCode(Class clazz, Class annotation, int 127 | requestCode) { 128 | for (Method method : clazz.getDeclaredMethods()) { 129 | if (method.getAnnotation(annotation) != null && 130 | isEqualRequestCodeFromAnnotation(method, annotation, requestCode)) { 131 | return method; 132 | } 133 | } 134 | return null; 135 | } 136 | 137 | private static boolean isEqualRequestCodeFromAnnotation(Method m, Class clazz, int requestCode) { 138 | if (clazz.equals(OnMPermissionDenied.class)) { 139 | return requestCode == m.getAnnotation(OnMPermissionDenied.class).value(); 140 | } else if (clazz.equals(OnMPermissionGranted.class)) { 141 | return requestCode == m.getAnnotation(OnMPermissionGranted.class).value(); 142 | } else if (clazz.equals(OnMPermissionNeverAskAgain.class)) { 143 | return requestCode == m.getAnnotation(OnMPermissionNeverAskAgain.class).value(); 144 | } else { 145 | return false; 146 | } 147 | } 148 | 149 | /** 150 | * ********************* reflect execute method ********************* 151 | */ 152 | 153 | private static void executeMethod(Object activity, Method executeMethod) { 154 | executeMethodWithParam(activity, executeMethod, new Object[]{}); 155 | } 156 | 157 | private static void executeMethodWithParam(Object activity, Method executeMethod, Object... args) { 158 | if (executeMethod != null) { 159 | try { 160 | if (!executeMethod.isAccessible()) { 161 | executeMethod.setAccessible(true); 162 | } 163 | executeMethod.invoke(activity, args); 164 | } catch (InvocationTargetException e) { 165 | e.printStackTrace(); 166 | } catch (IllegalAccessException e) { 167 | e.printStackTrace(); 168 | } 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/permission/annotation/OnMPermissionDenied.java: -------------------------------------------------------------------------------- 1 | package com.test.map.permission.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * register a method invoked when permission requests are denied without check never ask again. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface OnMPermissionDenied { 14 | int value(); 15 | } -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/permission/annotation/OnMPermissionGranted.java: -------------------------------------------------------------------------------- 1 | package com.test.map.permission.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * register a method invoked when permission requests are succeeded. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface OnMPermissionGranted { 14 | int value(); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/permission/annotation/OnMPermissionNeverAskAgain.java: -------------------------------------------------------------------------------- 1 | package com.test.map.permission.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * register some methods handling the user's choice to permanently deny permissions checking never ask again. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.METHOD) 13 | public @interface OnMPermissionNeverAskAgain { 14 | int value(); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/sqlite/MapHistoryBean.java: -------------------------------------------------------------------------------- 1 | package com.test.map.sqlite; 2 | 3 | public class MapHistoryBean { 4 | 5 | /** 6 | * map search History 7 | */ 8 | private long _id; 9 | private String Name; 10 | private String Address; 11 | private String Distance; 12 | private String Lat; 13 | private String Lon; 14 | public long get_id() { 15 | return _id; 16 | } 17 | 18 | public void set_id(long _id) { 19 | this._id = _id; 20 | } 21 | 22 | public String getName() { 23 | return Name; 24 | } 25 | 26 | public void setName(String name) { 27 | Name = name; 28 | } 29 | 30 | public String getAddress() { 31 | return Address; 32 | } 33 | 34 | public void setAddress(String address) { 35 | Address = address; 36 | } 37 | 38 | public String getDistance() { 39 | return Distance; 40 | } 41 | 42 | public void setDistance(String distance) { 43 | Distance = distance; 44 | } 45 | 46 | public String getLat() { 47 | return Lat; 48 | } 49 | 50 | public void setLat(String lat) { 51 | Lat = lat; 52 | } 53 | 54 | public String getLon() { 55 | return Lon; 56 | } 57 | 58 | public void setLon(String lon) { 59 | Lon = lon; 60 | } 61 | 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/sqlite/UserDataBaseOperate.java: -------------------------------------------------------------------------------- 1 | package com.test.map.sqlite; 2 | 3 | import android.content.ContentValues; 4 | import android.database.Cursor; 5 | import android.database.SQLException; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.text.TextUtils; 8 | import android.util.Log; 9 | 10 | import com.test.map.util.LogUtil; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | public class UserDataBaseOperate { 16 | 17 | private static final String TAG = "DBMap"; 18 | private static final boolean DEBUG = true; 19 | 20 | protected SQLiteDatabase mDB = null; 21 | 22 | public UserDataBaseOperate(SQLiteDatabase db) { 23 | if (null == db) { 24 | throw new NullPointerException("The db cannot be null."); 25 | } 26 | mDB = db; 27 | } 28 | public long insertToHistory(MapHistoryBean bean) { 29 | ContentValues values = new ContentValues(); 30 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_NAME, bean.getName()); 31 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_ADDRESS, bean.getAddress()); 32 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_DISTANCE, bean.getDistance()); 33 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_LAT, bean.getLat()); 34 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_LON, bean.getLon()); 35 | return mDB.insert(UserSQLiteOpenHelper.DATABASE_TABLE_USER, null, 36 | values); 37 | } 38 | 39 | public long updateHistory(MapHistoryBean bean) { 40 | ContentValues values = new ContentValues(); 41 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_NAME, bean.getName()); 42 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_ADDRESS, bean.getAddress()); 43 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_DISTANCE, bean.getDistance()); 44 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_LAT, bean.getLat()); 45 | values.put(UserSQLiteOpenHelper.MAP_HISTORY_LON, bean.getLon()); 46 | return mDB.update(UserSQLiteOpenHelper.DATABASE_TABLE_USER, values, 47 | "_id=?", new String[] { ""+bean.get_id() }); 48 | } 49 | 50 | public void deleteAll() { 51 | mDB.delete(UserSQLiteOpenHelper.DATABASE_TABLE_USER, null, null); 52 | LogUtil.e("userDataBaseOperate.deleteAll();22222222222222"); 53 | } 54 | 55 | public long deleteUserByname(String name){ 56 | 57 | return mDB.delete("user_info", "name=?", new String[]{name}); 58 | } 59 | 60 | public long getCount(String conditions, String[] args) { 61 | long count = 0; 62 | if (TextUtils.isEmpty(conditions)) { 63 | conditions = " 1 = 1 "; 64 | } 65 | StringBuilder builder = new StringBuilder(); 66 | builder.append("SELECT COUNT(1) AS count FROM "); 67 | builder.append(UserSQLiteOpenHelper.DATABASE_TABLE_USER).append(" "); 68 | builder.append("WHERE "); 69 | builder.append(conditions); 70 | if (DEBUG) 71 | Log.d(TAG, "SQL: " + builder.toString()); 72 | Cursor cursor = mDB.rawQuery(builder.toString(), args); 73 | if (null != cursor) { 74 | if (cursor.moveToNext()) { 75 | count = cursor.getLong(cursor.getColumnIndex("count")); 76 | } 77 | cursor.close(); 78 | } 79 | return count; 80 | } 81 | public List findAll() { 82 | List userList = new ArrayList(); 83 | //order by modifytime desc 84 | Cursor cursor = mDB.query(UserSQLiteOpenHelper.DATABASE_TABLE_USER, 85 | null, null, null, null, null, null); 86 | if (null != cursor) { 87 | while (cursor.moveToNext()) { 88 | MapHistoryBean bean = new MapHistoryBean(); 89 | bean.set_id(cursor.getLong(cursor 90 | .getColumnIndex(UserSQLiteOpenHelper.MAP_HISTORY_ID))); 91 | bean.setName(cursor.getString(cursor 92 | .getColumnIndex(UserSQLiteOpenHelper.MAP_HISTORY_NAME))); 93 | bean.setAddress(cursor.getString(cursor 94 | .getColumnIndex(UserSQLiteOpenHelper.MAP_HISTORY_ADDRESS))); 95 | bean.setDistance(cursor.getString(cursor 96 | .getColumnIndex(UserSQLiteOpenHelper.MAP_HISTORY_DISTANCE))); 97 | bean.setLat(cursor.getString(cursor 98 | .getColumnIndex(UserSQLiteOpenHelper.MAP_HISTORY_LAT))); 99 | bean.setLon(cursor.getString(cursor 100 | .getColumnIndex(UserSQLiteOpenHelper.MAP_HISTORY_LON))); 101 | userList.add(bean); 102 | } 103 | cursor.close(); 104 | } 105 | return userList; 106 | } 107 | 108 | // 删除全部数据 109 | public boolean delete() { 110 | 111 | String whereClause = "id=?"; 112 | try { 113 | mDB.delete("map_info", whereClause, null); 114 | } catch (SQLException e) { 115 | 116 | return false; 117 | } 118 | LogUtil.e("userDataBaseOperate.deleteAll();111"); 119 | return true; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/sqlite/UserSQLiteOpenHelper.java: -------------------------------------------------------------------------------- 1 | package com.test.map.sqlite; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | import android.database.sqlite.SQLiteOpenHelper; 6 | 7 | public class UserSQLiteOpenHelper extends SQLiteOpenHelper { 8 | 9 | private static String REMOTE_LIVE_DATABASE_NAME = "mapHistory.db"; 10 | private static int version = 1; 11 | public static final String DATABASE_TABLE_USER = "map_info"; 12 | public static final String MAP_HISTORY_ID = "_id"; 13 | public static final String MAP_HISTORY_NAME = "mapHistoryName"; 14 | public static final String MAP_HISTORY_ADDRESS = "mapHistoryAddress"; 15 | public static final String MAP_HISTORY_DISTANCE = "mapHistoryDistance"; 16 | public static final String MAP_HISTORY_LAT = "mapHistoryLat"; 17 | public static final String MAP_HISTORY_LON = "mapHistoryLon"; 18 | 19 | private final String REMOTE_LIVE_DATABASE_CREATE="create table if not exists " 20 | + DATABASE_TABLE_USER 21 | + " (_id integer primary key autoincrement, " 22 | + "mapHistoryName text not null," 23 | + "mapHistoryAddress text not null," 24 | + "mapHistoryDistance text not null," 25 | +"mapHistoryLat text not null," 26 | +"mapHistoryLon text not null);"; 27 | private static UserSQLiteOpenHelper mInstance = null; 28 | private static Context mContext; 29 | 30 | public static UserSQLiteOpenHelper getInstance(Context context) { 31 | if (null == mInstance) { 32 | mInstance = new UserSQLiteOpenHelper(context); 33 | mContext = context; 34 | } 35 | return mInstance; 36 | } 37 | 38 | private UserSQLiteOpenHelper(Context context) { 39 | super(context, REMOTE_LIVE_DATABASE_NAME, null, version); 40 | } 41 | 42 | @Override 43 | public void onCreate(SQLiteDatabase db) { 44 | db.execSQL(REMOTE_LIVE_DATABASE_CREATE); 45 | } 46 | 47 | @Override 48 | public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) { 49 | 50 | 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/util/AmapLocationTestUtil.java: -------------------------------------------------------------------------------- 1 | package com.test.map.util; 2 | 3 | 4 | import android.content.Context; 5 | 6 | import com.amap.api.location.AMapLocation; 7 | import com.amap.api.location.AMapLocationClient; 8 | import com.amap.api.location.AMapLocationClientOption; 9 | import com.amap.api.location.AMapLocationListener; 10 | 11 | 12 | /** 13 | * Created by FAN on 2017/5/8. 14 | */ 15 | 16 | 17 | public class AmapLocationTestUtil implements AMapLocationListener { 18 | public static AmapLocationTestUtil mAmapLocationTestUtil; 19 | public AMapLocationClient mLocationClient = null; 20 | public AMapLocationClientOption mlocationOption = null; 21 | Context context; 22 | 23 | public AmapLocationTestUtil(Context context) { 24 | this.context = context; 25 | mLocationClient = new AMapLocationClient(context); 26 | mlocationOption = new AMapLocationClientOption(); 27 | // 设置定位模式为高精度模式 28 | mlocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); 29 | mlocationOption.setGpsFirst(true); 30 | // 设置定位监听 31 | mLocationClient.setLocationListener(this); 32 | LogUtil.e("AmapLocationTestUtil init"); 33 | } 34 | 35 | public static AmapLocationTestUtil getInstance(Context context) { 36 | if (mAmapLocationTestUtil == null) { 37 | mAmapLocationTestUtil = new AmapLocationTestUtil(context); 38 | } 39 | return mAmapLocationTestUtil; 40 | } 41 | 42 | @Override 43 | public void onLocationChanged(AMapLocation aMapLocation) { 44 | if (null != aMapLocation) { 45 | MapUtil.latLonPoint = MapUtil.getLatLonPoint(aMapLocation); 46 | MapUtil.LOCATION_PROVINCE = MapUtil.getProvince(aMapLocation); 47 | MapUtil.LOCATION_CITY = MapUtil.getCity(aMapLocation); 48 | if (null != MapUtil.latLonPoint) { 49 | MapUtil.latLon = MapUtil.convertToLatLng(MapUtil.latLonPoint); 50 | } 51 | LogUtil.e("loction__" + MapUtil.latLonPoint + "\n" + MapUtil.LOCATION_CITY + "\n" + MapUtil.latLon); 52 | } 53 | } 54 | 55 | public void startLocation() { 56 | if (mLocationClient != null) { 57 | mLocationClient.startLocation(); 58 | } 59 | } 60 | 61 | public void stopLocation() { 62 | if (mLocationClient != null) { 63 | mLocationClient.stopLocation(); 64 | } 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/util/LogUtil.java: -------------------------------------------------------------------------------- 1 | package com.test.map.util; 2 | 3 | /** 4 | * Created by Administrator on 2017/5/8. 5 | */ 6 | 7 | public class LogUtil { 8 | private static final String TAG = "DEBUG_FAN"; 9 | private static final boolean LOG = true; 10 | 11 | public static void i(String msg) { 12 | if (LOG) 13 | android.util.Log.i(TAG, msg); 14 | } 15 | 16 | public static void d(String msg) { 17 | if (LOG) 18 | android.util.Log.d(TAG, msg); 19 | } 20 | 21 | public static void w(String msg) { 22 | if (LOG) 23 | android.util.Log.w(TAG, msg); 24 | } 25 | 26 | public static void w(String msg, Throwable throwable) { 27 | if (LOG) 28 | android.util.Log.w(TAG, msg, throwable); 29 | } 30 | 31 | public static void v(String msg) { 32 | if (LOG) 33 | android.util.Log.v(TAG, msg); 34 | } 35 | 36 | public static void e(String msg) { 37 | if (LOG) 38 | android.util.Log.e(TAG, msg); 39 | } 40 | 41 | public static void e(String msg, Throwable throwable) { 42 | if (LOG) 43 | android.util.Log.e(TAG, msg, throwable); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/util/MapUtil.java: -------------------------------------------------------------------------------- 1 | package com.test.map.util; 2 | 3 | import android.location.Location; 4 | 5 | import com.amap.api.location.AMapLocation; 6 | import com.amap.api.maps.AMapUtils; 7 | import com.amap.api.maps.model.LatLng; 8 | import com.amap.api.services.core.LatLonPoint; 9 | 10 | import java.text.DecimalFormat; 11 | 12 | /** 13 | * Created by FAN on 2017/5/8. 14 | */ 15 | 16 | public class MapUtil { 17 | public static final String Kilometer = "\u516c\u91cc";// "公里"; 18 | public static final String Meter = "\u7c73";// "米"; 19 | public static LatLonPoint latLonPoint = null; //经纬度 20 | public static LatLng latLon = null; //经纬度 21 | public static String LOCATION_PROVINCE = null; //所在省份 22 | public static String LOCATION_CITY = "深圳市"; //所在城市 23 | 24 | public static int PathPlanningMode = 0; //路径规划模式 (默认、距离最短、时间最短、) 25 | 26 | public static String DRIVING_SINGLE_DEFAULT_TIME = " "; // 默认的 规划路径 时间 27 | public static String DRIVING_SINGLE_DEFAULT_DISTANCE = " "; // 默认的 规划路径 距离 28 | public static String DRIVING_SINGLE_SHORTEST_TIME = " "; // 距离最短 规划路径 时间 29 | public static String DRIVING_SINGLE_SHORTEST_DISTANCE = " "; // 距离最短 规划路径 距离 30 | public static String DRIVING_SINGLE_AVOID_CONGESTION_TIME = " "; // 避免拥堵 规划路径 时间 31 | public static String DRIVING_SINGLE_AVOID_CONGESTION_DISTANCE = " "; // 避免拥堵 规划路径 距离 32 | 33 | public static boolean IsEmptyOrNullString(String s) { 34 | return (s == null) || (s.trim().length() == 0); 35 | } 36 | 37 | /** 38 | * 根据定位结果返回 LatLonPoint 39 | * 40 | * @param 41 | * @return 42 | */ 43 | public synchronized static LatLonPoint getLatLonPoint(AMapLocation location) { 44 | if (null == location) { 45 | return null; 46 | } 47 | latLonPoint = new LatLonPoint(location.getLatitude(), location.getLongitude()); 48 | return latLonPoint; 49 | } 50 | 51 | /** 52 | * 根据定位结果返回 LatLng 53 | * 54 | * @param 55 | * @return 56 | */ 57 | public synchronized static LatLng getLatLng(Location location) { 58 | if (null == location) { 59 | return null; 60 | } 61 | latLon = new LatLng(location.getLatitude(), location.getLongitude()); 62 | return latLon; 63 | } 64 | 65 | /** 66 | * 根据定位结果返回 String City 67 | * 68 | * @param 69 | * @return 70 | */ 71 | public synchronized static String getProvince(AMapLocation location) { 72 | if (null == location) { 73 | return null; 74 | } 75 | LOCATION_PROVINCE = location.getProvince(); 76 | return LOCATION_PROVINCE; 77 | } 78 | 79 | /** 80 | * 根据定位结果返回 String Province 81 | * 82 | * @param 83 | * @return 84 | */ 85 | public synchronized static String getCity(AMapLocation location) { 86 | if (null == location) { 87 | return null; 88 | } 89 | LOCATION_CITY = location.getCity(); 90 | return LOCATION_CITY; 91 | } 92 | 93 | /** 94 | * 把LatLng对象转化为LatLonPoint对象 95 | */ 96 | public static LatLonPoint convertToLatLonPoint(LatLng latlon) { 97 | return new LatLonPoint(latlon.latitude, latlon.longitude); 98 | } 99 | 100 | /** 101 | * 把LatLonPoint对象转化为LatLon对象 102 | */ 103 | public static LatLng convertToLatLng(LatLonPoint latLonPoint) { 104 | return new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude()); 105 | } 106 | 107 | /** 108 | * 计算两点间距离 LatLng 109 | */ 110 | public static String distanceLatLng(LatLng startLatLng, LatLng endLatLng) { 111 | double distanceMeter = AMapUtils.calculateLineDistance(startLatLng, endLatLng); //得到两点间距离/米 112 | DecimalFormat df = new DecimalFormat("######0.00"); //去掉double 后面0.00 后面的 113 | String distanceKm = df.format(distanceMeter / 1000); //化单位为千米 114 | return distanceKm; 115 | } 116 | 117 | /** 118 | * 这里用到的是 规划路径算路时间 119 | * 120 | * @param second 121 | * @return 122 | */ 123 | public static String getFriendlyTime(int second) { 124 | if (second > 3600) { 125 | int hour = second / 3600; 126 | int miniate = (second % 3600) / 60; 127 | return hour + "小时" + miniate + "分钟"; 128 | } 129 | if (second >= 60) { 130 | int miniate = second / 60; 131 | return miniate + "分钟"; 132 | } 133 | return second + "秒"; 134 | } 135 | 136 | 137 | public static String getFriendlyLength(int lenMeter) { 138 | if (lenMeter > 10000) // 10 km 139 | { 140 | int dis = lenMeter / 1000; 141 | return dis + Kilometer; 142 | } 143 | 144 | if (lenMeter > 1000) { 145 | float dis = (float) lenMeter / 1000; 146 | DecimalFormat fnum = new DecimalFormat("##0.0"); 147 | String dstr = fnum.format(dis); 148 | return dstr + Kilometer; 149 | } 150 | 151 | if (lenMeter > 100) { 152 | int dis = lenMeter / 50 * 50; 153 | return dis + Meter; 154 | } 155 | 156 | int dis = lenMeter / 10 * 10; 157 | if (dis == 0) { 158 | dis = 10; 159 | } 160 | 161 | return dis + Meter; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /app/src/main/java/com/test/map/util/OffLineMapUtils.java: -------------------------------------------------------------------------------- 1 | package com.test.map.util; 2 | 3 | import android.content.Context; 4 | import android.os.Environment; 5 | 6 | public class OffLineMapUtils { 7 | /** 8 | * 获取map 缓存和读取目录 9 | */ 10 | public static String getSdCacheDir(Context context) { 11 | if (Environment.getExternalStorageState().equals( 12 | Environment.MEDIA_MOUNTED)) { 13 | java.io.File fExternalStorageDirectory = Environment 14 | .getExternalStorageDirectory(); 15 | java.io.File autonaviDir = new java.io.File( 16 | fExternalStorageDirectory, "CRVamapsdk"); 17 | boolean result = false; 18 | if (!autonaviDir.exists()) { 19 | result = autonaviDir.mkdir(); 20 | } 21 | java.io.File minimapDir = new java.io.File(autonaviDir, 22 | "offlineMap"); 23 | if (!minimapDir.exists()) { 24 | result = minimapDir.mkdir(); 25 | } 26 | return minimapDir.toString() + "/"; 27 | } else { 28 | return ""; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libGNaviData.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libGNaviData.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libGNaviGuide.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libGNaviGuide.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libGNaviMap.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libGNaviMap.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libGNaviMapex.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libGNaviMapex.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libGNaviPos.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libGNaviPos.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libGNaviRoute.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libGNaviRoute.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libGNaviSearch.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libGNaviSearch.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libGNaviUtils.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libGNaviUtils.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libRoadLineRebuildAPI.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libRoadLineRebuildAPI.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libmsc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libmsc.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/librtbt800.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/librtbt800.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libwtbt800.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/jniLibs/armeabi/libwtbt800.so -------------------------------------------------------------------------------- /app/src/main/res/GaodeDemo.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/GaodeDemo.apk -------------------------------------------------------------------------------- /app/src/main/res/GaodeDemo_主页.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/GaodeDemo_主页.png -------------------------------------------------------------------------------- /app/src/main/res/GaodeDemo_去这里.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/GaodeDemo_去这里.png -------------------------------------------------------------------------------- /app/src/main/res/GaodeDemo_周边搜索.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/GaodeDemo_周边搜索.png -------------------------------------------------------------------------------- /app/src/main/res/GaodeDemo_导航.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/GaodeDemo_导航.png -------------------------------------------------------------------------------- /app/src/main/res/GaodeDemo_策略选择.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/GaodeDemo_策略选择.png -------------------------------------------------------------------------------- /app/src/main/res/anim/popup_enter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/anim/popup_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/anim/translate_poi_frgment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/amap_car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/amap_car.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/amap_end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/amap_end.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/amap_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/amap_start.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/amap_through.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/amap_through.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bt_search_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/bt_search_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/emotionstore_progresscancelbtn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/emotionstore_progresscancelbtn.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/go_where.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/go_where.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/go_where_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/go_where_2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ly_frame_line.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_bt_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_bt_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_bt_bottm_bg_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_bt_bottm_bg_l.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_bt_bottm_bg_w.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_bt_bottm_bg_w.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_destination_press.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_go_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_go_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_go_where_iv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_go_where_iv.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_history_go_where_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_history_go_where_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_history_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_history_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_history_list_divider.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_nav_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_nav_select.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_poi_search_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_poi_search_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/map_search_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/map_search_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/nav_start_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/nav_start_bg.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/out_call_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/out_call_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/phone_book_icon_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/phone_book_icon_blue.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/phone_dial_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/phone_dial_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/phone_dial_icon_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/phone_dial_icon_blue.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/phone_emergency.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/phone_emergency.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/po_seekbar.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/poi_marker_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/poi_marker_pressed.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/setting_list_divider.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/wel_bt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mapeifan/GaodeMap/12c715df873bc980113977b8f8769a044a35106d/app/src/main/res/drawable/wel_bt.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_map.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | 11 |