├── .classpath ├── .gitignore ├── .project ├── AndroidManifest.xml ├── LICENSE ├── README.md ├── apk └── MoveExample.apk ├── ic_launcher-web.png ├── libs ├── Android_3DMap_V2.4.0.jar ├── android-support-v4.jar ├── armeabi-v7a │ ├── .DS_Store │ ├── libamapv304.so │ └── libamapv304ex.so ├── armeabi │ ├── .DS_Store │ ├── libamapv304.so │ └── libamapv304ex.so └── x86 │ ├── libamapv304.so │ └── libamapv304ex.so ├── pic └── move.gif ├── proguard-project.txt ├── project.properties ├── res ├── drawable-hdpi │ ├── ic_launcher.png │ └── marker.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── layout │ └── activity_main.xml └── values │ ├── dimens.xml │ └── strings.xml └── src └── com └── amap └── api └── example └── MainActivity.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | 3 | 4 | # Files for the Dalvik VM 5 | *.dex 6 | 7 | # Java class files 8 | *.class 9 | 10 | # Generated files 11 | bin/ 12 | gen/ 13 | 14 | # Gradle files 15 | .gradle/ 16 | build/ 17 | /*/build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | MoveExample 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |   43 | 44 | 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android_Move_Example 2 | 工程最新代码迁移至 [这里](https://github.com/amap-demo/android-smooth-move). 3 | -------------------------------------------------------------------------------- /apk/MoveExample.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/apk/MoveExample.apk -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/ic_launcher-web.png -------------------------------------------------------------------------------- /libs/Android_3DMap_V2.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/Android_3DMap_V2.4.0.jar -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/android-support-v4.jar -------------------------------------------------------------------------------- /libs/armeabi-v7a/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/armeabi-v7a/.DS_Store -------------------------------------------------------------------------------- /libs/armeabi-v7a/libamapv304.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/armeabi-v7a/libamapv304.so -------------------------------------------------------------------------------- /libs/armeabi-v7a/libamapv304ex.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/armeabi-v7a/libamapv304ex.so -------------------------------------------------------------------------------- /libs/armeabi/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/armeabi/.DS_Store -------------------------------------------------------------------------------- /libs/armeabi/libamapv304.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/armeabi/libamapv304.so -------------------------------------------------------------------------------- /libs/armeabi/libamapv304ex.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/armeabi/libamapv304ex.so -------------------------------------------------------------------------------- /libs/x86/libamapv304.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/x86/libamapv304.so -------------------------------------------------------------------------------- /libs/x86/libamapv304ex.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/libs/x86/libamapv304ex.so -------------------------------------------------------------------------------- /pic/move.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/pic/move.gif -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-21 15 | -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-hdpi/marker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/res/drawable-hdpi/marker.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amapapi/Android_Move_Example/5687c5c6b1da69d7d643731723bc3785ae9ecab0/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | MoveExample 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/com/amap/api/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.amap.api.example; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Color; 5 | import android.os.Bundle; 6 | 7 | import com.amap.api.maps.AMap; 8 | import com.amap.api.maps.MapView; 9 | import com.amap.api.maps.model.BitmapDescriptorFactory; 10 | import com.amap.api.maps.model.LatLng; 11 | import com.amap.api.maps.model.Marker; 12 | import com.amap.api.maps.model.MarkerOptions; 13 | import com.amap.api.maps.model.Polyline; 14 | import com.amap.api.maps.model.PolylineOptions; 15 | 16 | public class MainActivity extends Activity { 17 | 18 | private MapView mMapView; 19 | private AMap mAmap; 20 | private Polyline mVirtureRoad; 21 | private Marker mMoveMarker; 22 | 23 | // 通过设置间隔时间和距离可以控制速度和图标移动的距离 24 | private static final int TIME_INTERVAL = 80; 25 | private static final double DISTANCE = 0.0001; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main); 31 | mMapView = (MapView) findViewById(R.id.map); 32 | 33 | mMapView.onCreate(savedInstanceState); 34 | mAmap = mMapView.getMap(); 35 | initRoadData(); 36 | moveLooper(); 37 | } 38 | 39 | private void initRoadData() { 40 | // 116.504505 39.931057 41 | double centerLatitude = 39.916049; 42 | double centerLontitude = 116.399792; 43 | double deltaAngle = Math.PI / 180 * 5; 44 | double radius = 0.02; 45 | PolylineOptions polylineOptions = new PolylineOptions(); 46 | for (double i = 0; i < Math.PI * 2; i = i + deltaAngle) { 47 | float latitude = (float) (-Math.cos(i) * radius + centerLatitude); 48 | float longtitude = (float) (Math.sin(i) * radius + centerLontitude); 49 | polylineOptions.add(new LatLng(latitude, longtitude)); 50 | if (i > Math.PI) { 51 | deltaAngle = Math.PI / 180 * 30; 52 | } 53 | } 54 | float latitude = (float) (-Math.cos(0) * radius + centerLatitude); 55 | float longtitude = (float) (Math.sin(0) * radius + centerLontitude); 56 | polylineOptions.add(new LatLng(latitude, longtitude)); 57 | 58 | 59 | 60 | 61 | // polylineOptions.add(new LatLng(39.954368, 116.478038)); 62 | // polylineOptions.add(new LatLng(39.92515, 116.510997)); 63 | // polylineOptions.add(new LatLng(39.892198, 116.439449)); 64 | // polylineOptions.add(new LatLng(39.919324, 116.379367)); 65 | // polylineOptions.add(new LatLng(39.951704, 116.356708)); 66 | // 67 | // 68 | // 69 | // 70 | // polylineOptions.add(new LatLng(39.970914, 116.408206)); 71 | // 72 | // polylineOptions.add(new LatLng(40.005899, 116.467601)); 73 | // polylineOptions.add(new LatLng(39.954368, 116.478038)); 74 | polylineOptions.width(10); 75 | polylineOptions.color(Color.RED); 76 | mVirtureRoad = mAmap.addPolyline(polylineOptions); 77 | MarkerOptions markerOptions = new MarkerOptions(); 78 | markerOptions.setFlat(true); 79 | markerOptions.anchor(0.5f, 0.5f); 80 | markerOptions.icon(BitmapDescriptorFactory 81 | .fromResource(R.drawable.marker)); 82 | markerOptions.position(polylineOptions.getPoints().get(0)); 83 | mMoveMarker = mAmap.addMarker(markerOptions); 84 | mMoveMarker.setRotateAngle((float) getAngle(0)); 85 | 86 | } 87 | 88 | /** 89 | * 根据点获取图标转的角度 90 | */ 91 | private double getAngle(int startIndex) { 92 | if ((startIndex + 1) >= mVirtureRoad.getPoints().size()) { 93 | throw new RuntimeException("index out of bonds"); 94 | } 95 | LatLng startPoint = mVirtureRoad.getPoints().get(startIndex); 96 | LatLng endPoint = mVirtureRoad.getPoints().get(startIndex + 1); 97 | return getAngle(startPoint, endPoint); 98 | } 99 | 100 | /** 101 | * 根据两点算取图标转的角度 102 | */ 103 | private double getAngle(LatLng fromPoint, LatLng toPoint) { 104 | double slope = getSlope(fromPoint, toPoint); 105 | if (slope == Double.MAX_VALUE) { 106 | if (toPoint.latitude > fromPoint.latitude) { 107 | return 0; 108 | } else { 109 | return 180; 110 | } 111 | } 112 | float deltAngle = 0; 113 | if ((toPoint.latitude - fromPoint.latitude) * slope < 0) { 114 | deltAngle = 180; 115 | } 116 | double radio = Math.atan(slope); 117 | double angle = 180 * (radio / Math.PI) + deltAngle - 90; 118 | return angle; 119 | } 120 | 121 | /** 122 | * 根据点和斜率算取截距 123 | */ 124 | private double getInterception(double slope, LatLng point) { 125 | 126 | double interception = point.latitude - slope * point.longitude; 127 | return interception; 128 | } 129 | 130 | /** 131 | * 算取斜率 132 | */ 133 | private double getSlope(int startIndex) { 134 | if ((startIndex + 1) >= mVirtureRoad.getPoints().size()) { 135 | throw new RuntimeException("index out of bonds"); 136 | } 137 | LatLng startPoint = mVirtureRoad.getPoints().get(startIndex); 138 | LatLng endPoint = mVirtureRoad.getPoints().get(startIndex + 1); 139 | return getSlope(startPoint, endPoint); 140 | } 141 | 142 | /** 143 | * 算斜率 144 | */ 145 | private double getSlope(LatLng fromPoint, LatLng toPoint) { 146 | if (toPoint.longitude == fromPoint.longitude) { 147 | return Double.MAX_VALUE; 148 | } 149 | double slope = ((toPoint.latitude - fromPoint.latitude) / (toPoint.longitude - fromPoint.longitude)); 150 | return slope; 151 | 152 | } 153 | 154 | /** 155 | * 方法必须重写 156 | */ 157 | @Override 158 | protected void onResume() { 159 | super.onResume(); 160 | mMapView.onResume(); 161 | } 162 | 163 | /** 164 | * 方法必须重写 165 | */ 166 | @Override 167 | protected void onPause() { 168 | super.onPause(); 169 | mMapView.onPause(); 170 | } 171 | 172 | /** 173 | * 方法必须重写 174 | */ 175 | @Override 176 | protected void onSaveInstanceState(Bundle outState) { 177 | super.onSaveInstanceState(outState); 178 | mMapView.onSaveInstanceState(outState); 179 | } 180 | 181 | /** 182 | * 方法必须重写 183 | */ 184 | @Override 185 | protected void onDestroy() { 186 | super.onDestroy(); 187 | mMapView.onDestroy(); 188 | } 189 | 190 | /** 191 | * 计算每次移动的距离 192 | */ 193 | private double getMoveDistance(double slope) { 194 | if (slope == Double.MAX_VALUE||slope==0) { 195 | return DISTANCE; 196 | } 197 | return Math.abs((DISTANCE * slope) / Math.sqrt(1 + slope * slope)); 198 | } 199 | 200 | /** 201 | * 判断是否为反序 202 | * */ 203 | private boolean isReverse(LatLng startPoint,LatLng endPoint,double slope){ 204 | if(slope==0){ 205 | return startPoint.longitude>endPoint.longitude; 206 | } 207 | return (startPoint.latitude > endPoint.latitude); 208 | 209 | } 210 | 211 | /** 212 | * 获取循环初始值大小 213 | * */ 214 | private double getStart(LatLng startPoint,double slope){ 215 | if(slope==0){ 216 | return startPoint.longitude; 217 | } 218 | return startPoint.latitude; 219 | } 220 | 221 | /** 222 | * 获取循环结束大小 223 | * */ 224 | private double getEnd(LatLng endPoint,double slope){ 225 | if(slope==0){ 226 | return endPoint.longitude; 227 | } 228 | return endPoint.latitude; 229 | } 230 | 231 | 232 | 233 | /** 234 | * 循环进行移动逻辑 235 | */ 236 | public void moveLooper() { 237 | new Thread() { 238 | 239 | public void run() { 240 | while (true) { 241 | for (int i = 0; i < mVirtureRoad.getPoints().size() - 1; i++) { 242 | 243 | 244 | LatLng startPoint = mVirtureRoad.getPoints().get(i); 245 | LatLng endPoint = mVirtureRoad.getPoints().get(i + 1); 246 | mMoveMarker 247 | .setPosition(startPoint); 248 | mMoveMarker.setRotateAngle((float) getAngle(startPoint, 249 | endPoint)); 250 | 251 | double slope = getSlope(startPoint, endPoint); 252 | boolean isReverse =isReverse(startPoint, endPoint, slope); 253 | double moveDistance = isReverse ? getMoveDistance(slope) : -1 * getMoveDistance(slope); 254 | double intercept = getInterception(slope, startPoint); 255 | for(double j=getStart(startPoint, slope); (j > getEnd(endPoint, slope))==isReverse;j = j 256 | - moveDistance){ 257 | LatLng latLng = null; 258 | if(slope==0){ 259 | latLng = new LatLng(startPoint.latitude, j); 260 | } 261 | else if (slope == Double.MAX_VALUE) { 262 | latLng = new LatLng(j, startPoint.longitude); 263 | } 264 | 265 | else { 266 | 267 | latLng = new LatLng(j, (j - intercept) / slope); 268 | } 269 | mMoveMarker.setPosition(latLng); 270 | try { 271 | Thread.sleep(TIME_INTERVAL); 272 | } catch (InterruptedException e) { 273 | e.printStackTrace(); 274 | } 275 | } 276 | 277 | } 278 | } 279 | } 280 | 281 | }.start(); 282 | } 283 | 284 | } 285 | --------------------------------------------------------------------------------