Repository: prabhat1707/EasyWayLocation Branch: master Commit: 2511fa2038a8 Files: 53 Total size: 152.6 KB Directory structure: gitextract_l0dynpvp/ ├── .github/ │ └── ISSUE_TEMPLATE/ │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README-zh_CN.md ├── README.md ├── app/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ ├── debug/ │ │ └── res/ │ │ └── values/ │ │ └── google_maps_api.xml │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── prabhat/ │ │ │ └── locationsample/ │ │ │ ├── CustomInfoWindowForGoogleMap.kt │ │ │ ├── MainActivity.java │ │ │ └── MapsActivity.kt │ │ └── res/ │ │ ├── drawable/ │ │ │ └── ic_launcher_background.xml │ │ ├── drawable-v24/ │ │ │ └── ic_launcher_foreground.xml │ │ ├── layout/ │ │ │ ├── activity_main.xml │ │ │ ├── activity_maps.xml │ │ │ └── marker_window.xml │ │ ├── mipmap-anydpi-v26/ │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ └── values/ │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── release/ │ └── res/ │ └── values/ │ └── google_maps_api.xml ├── build.gradle ├── easywaylocation/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── com/ │ │ └── example/ │ │ └── easywaylocation/ │ │ └── ExampleInstrumentedTest.java │ ├── main/ │ │ ├── AndroidManifest.xml │ │ ├── java/ │ │ │ └── com/ │ │ │ └── example/ │ │ │ └── easywaylocation/ │ │ │ ├── AddressHelper.java │ │ │ ├── EasyWayLocation.java │ │ │ ├── GetLocationDetail.java │ │ │ ├── Listener.java │ │ │ ├── LocationData.java │ │ │ ├── Logger.kt │ │ │ ├── RequestCallback.java │ │ │ └── draw_path/ │ │ │ ├── DataParser.java │ │ │ ├── DirectionUtil.kt │ │ │ ├── MapAnimator.kt │ │ │ ├── PolyLineDataBean.kt │ │ │ ├── PolylineBean.kt │ │ │ └── RouteEvaluator.java │ │ └── res/ │ │ └── values/ │ │ └── strings.xml │ └── test/ │ └── java/ │ └── com/ │ └── example/ │ └── easywaylocation/ │ └── ExampleUnitTest.java ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: Bug report about: Create a report to help us improve title: '' labels: '' assignees: '' --- **Describe the bug** A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error **Expected behavior** A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - OS: [e.g. iOS] - Browser [e.g. chrome, safari] - Version [e.g. 22] **Smartphone (please complete the following information):** - Device: [e.g. iPhone6] - OS: [e.g. iOS8.1] - Browser [e.g. stock browser, safari] - Version [e.g. 22] **Additional context** Add any other context about the problem here. ================================================ FILE: .github/ISSUE_TEMPLATE/feature_request.md ================================================ --- name: Feature request about: Suggest an idea for this project title: '' labels: '' assignees: '' --- **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context or screenshots about the feature request here. ================================================ FILE: .gitignore ================================================ *.iml .gradle /local.properties .idea .DS_Store /build /captures .externalNativeBuild ================================================ FILE: CODE_OF_CONDUCT.md ================================================ # Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at prabhat.rai1707@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [2018] [Prabhat Rai] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README-zh_CN.md ================================================ # Android - EasyWayLocation 该库包含与谷歌位置相关的所有实用程序。例如,获取经纬度、地址和位置设置对话框、绘制路线等 [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-EasyWayLocation-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/6880) ## 有什么新功能 Ver 2.4 - 弧线绘制 a. 简单的 b. 动画. - 在起点和终点之间绘制弧线路线 - 现在,Dev 可以动态更改参数,例如起点、航点等 - 获取arrayList和HashMap中的折线详细信息类 - 使用 TAG 为弧形和航路点折线清除折线 - 修复重大崩溃 - 在示例文件夹中创建了一个曲目演示以供更多使用帮助 # 演示图像和 Gif: ![IMages1](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2F1.png?alt=media&token=0f7b6430-7dac-453e-879f-f0523792fb31) ![alt Setting IMages2](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2F2.png?alt=media&token=a0aa40d3-2f84-4886-9579-79fdd694290d) ![alt Setting IMages3](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2F3.png?alt=media&token=412a7e86-0363-4e97-bf01-e130865d015f) ![gif1](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2Faniated_forgithub.gif?alt=media&token=d17c187f-8192-4d2f-a44e-26020acfd3eb) ![gif2](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2Fgif_for_github.gif?alt=media&token=060e72c1-a3fd-4090-8589-7e85ed598b0e) # 先决条件 - Android 16 # 安装 ## Step 1:- 将其添加到存储库末尾的根 build.gradle 中: ```` all projects { repositories { ... maven { url 'https://jitpack.io' } } } ```` ## Step 2:- 添加 dependency: ```` dependencies { implementation 'com.github.prabhat1707:EasyWayLocation:2.4' } ```` ### 库使用 java 8 字节码,所以不要忘记在应用程序的 build.gradle 文件中启用 java 8。 ```` android { compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } } ```` # Usage ###### 如果设备运行 Android 6.0 或更高版本,并且您的应用的目标 SDK 为 29 或更高版本,则首先检查位置的权限,然后调用它。 ## 添加所需的权限 为了优越的位置 (GPS location), 在您的添加以下权限 AndroidManifest.xml: ```` ```` For coarse location (network location), add the following permission in your AndroidManifest.xml: ```` ```` # 从设备中检索位置 ```` public class MainActivity extends AppCompatActivity implements Listener { EasyWayLocation easyWayLocation; private TextView location, latLong, diff; private Double lati, longi; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //-- easyWayLocation = new EasyWayLocation(this, false,false,this); } @Override public void locationOn() { Toast.makeText(this, "Location ON", Toast.LENGTH_SHORT).show(); } @Override public void currentLocation(Location location) { StringBuilder data = new StringBuilder(); data.append(location.getLatitude()); data.append(" , "); data.append(location.getLongitude()); latLong.setText(data); getLocationDetail.getAddress(location.getLatitude(), location.getLongitude(), "xyz"); } @Override public void locationCancelled() { Toast.makeText(this, "Location Cancelled", Toast.LENGTH_SHORT).show(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case LOCATION_SETTING_REQUEST_CODE: easyWayLocation.onActivityResult(resultCode); break; } } @Override protected void onResume() { super.onResume(); easyWayLocation.startLocation(); } @Override protected void onPause() { super.onPause(); easyWayLocation.endUpdates(); } } ```` # 位置通知器 ```` @Override public void locationOn() { Toast.makeText(this, "Location ON", Toast.LENGTH_SHORT).show(); } @Override public void currentLocation(Location location){ // give lat and long at every interval } @Override public void locationCancelled() { // location not on } ```` # 构造函数选项 ## 要记住的要点 - 如果您只想要最后一个位置,则将其传递为 true,如果为 false,则根据默认位置请求为您提供位置更新。 - 如果您不通过,则它需要默认位置请求,或者您也可以通过您的位置请求(参见构造函数 2nd)。 ```` Context context = this; boolean requireFineGranularity = false; new EasyWayLocation(this, requireLastLocation = false,isDebuggable = true/false,listner = this); or request = new LocationRequest(); request.setInterval(10000); request.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); new EasyWayLocation(this,locationRequest = request , requireLastLocation = false,isDebuggable = true/false,listner = this); ```` ## 计算两点之间的距离 ```` double startLatitude = 59.95; double startLongitude = 30.3; double endLatitude = 44.84; double endLongitude = -0.58; location.calculateDistance(startLatitude, startLongitude, endLatitude, endLongitude); // or Point startPoint = new EasyWayLocation.Point(59.95, 30.3); Point endPoint = new EasyWayLocation.Point(44.84, -0.58); location.calculateDistance(startPoint, endPoint); ```` ## 更新获取位置的地址详细信息。 - if you want an address from the current location then you need to pass key and context. - why I want key here if android already provides Geocoder because in some cases or some devices geocoder not work well and throws Exception, so in that case, I use google geocode API for fetch address. - For this, you need to implement Callback, LocationData.AddressCallBack ```` GetLocationDetail getLocationDetail = new GetLocationDetail(callback = this, context = this); getLocationDetail.getAddress(location.getLatitude(), location.getLongitude(), key = "xyz"); ```` ## 谷歌地图路线 #### 如果您想在您的应用程序中添加地图路线功能,您可以通过添加 DirectionUtil 类将其与此库一起使用,以使您更轻松地工作。这是 lib 将帮助您绘制两点 LatLng 与航点之间的路线图。 ## 当您的 GoogleMap 准备就绪时 #### 确保在谷歌开发者控制台中启用谷歌地图和谷歌地图方向。 #### 首先初始化Direction Util ```` wayPoints.add(LatLng(37.423669, -122.090168)) wayPoints.add(LatLng(37.420930, -122.085362)) val directionUtil = DirectionUtil.Builder() .setDirectionKey("xyz") .setOrigin(LatLng(37.421481, -122.092156)) .setWayPoints(wayPoints) .setGoogleMap(mMap) .setPolyLinePrimaryColor(R.color.black) .setPolyLineWidth(5) .setPathAnimation(true) .setCallback(this) .setPolylineTag(WAY_POINT_TAG) .setDestination(LatLng(37.421519, -122.086809)) .build() ```` #### 为路线绘制添加以下行 #### 先调用init再调用drawRoute ```` directionUtil.initPath() directionUtil.drawPath(WAY_POINT_TAG) ```` #### 现在从 v2.4 开始,您可以在路径之间更改原点、颜色等 ```` directionUtil.serOrigin(LatLng(driverCurrentLocation.latitude,driverCurrentLocation.longitude),wayPoints) ```` #### 为圆弧绘制添加下面的行 ```` directionUtil.drawArcDirection(LatLng(37.421481, -122.092156),LatLng(37.421519, -122.086809),0.5,ARC_POINT_TAG) ```` #### 添加下面的行以根据相应的TAG删除折线 ```` directionUtil.clearPolyline(WAY_POINT_TAG) ```` # 其中有两种情况: - 像优步这样的动画 - 没有动画。 1.带动画 - setPathAnimation = true ![gif1](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2Fanimation_route.gif?alt=media&token=97af3e8c-e302-41af-b93b-e8b85b47d9e7) 2.没有动画 - setPathAnimation = false - change its color by, setPolyLinePrimaryColor() property ![gif2](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2Fnormal_routw.gif?alt=media&token=76e35316-2e76-4d4d-9099-98f3f0678b34) ## 回调 #### 当路由绘制路径完成时,调用下面的回调 ```` override fun pathFindFinish(polyLineDetails: HashMap) { for (i in polyLineDetails.keys){ Log.v("sample",polyLineDetails[i]?.time) } } ```` here, polyLineDetails contain each polyline or route detail as time, distance and road summary. #### 您还可以更改路线动画的不同属性,如延迟、原色、次要颜色等,只需探索它即可。 #### 错误,功能请求 发现错误?缺少什么?反馈是改进项目的重要组成部分,所以,请 open an issue # 执照 ```` 版权所有 (c) 根据 Apache 许可证 2.0 版(“许可证”)获得许可; 除非遵守许可,否则您不得使用此文件。 您可以在以下网址获取许可证的副本 http://www.apache.org/licenses/LICENSE-2.0 除非适用法律要求 w 或书面同意,软件 根据许可分发是在“原样”基础上分发的, 没有任何明示或暗示的保证或条件。 请参阅许可以了解特定语言的管理权限和 许可证下的限制。 ```` ================================================ FILE: README.md ================================================ ---
See 1 Available Translations 🇨🇳

- [🇨🇳 简体中文](./README-zh_CN.md)

--- # Android - EasyWayLocation This library contains all utils related to google location. like, getting lat or long, Address and Location Setting dialog, Draw Route, etc [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-EasyWayLocation-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/6880) ## What's New in Ver 2.4 - Arc Route Draw a. simple. b. animation. - Draw Arc route between origin and destination. - Now , Dev can change parameter dynamically like origin, waypoints, etc - Get polyline details class in arrayList and HashMap. - Clear Polyline by using TAG for both Arc and waypoints polylines. - Fix Major Crash - Created one track demo in sample folder for more usage Help # Demo Images and Gif: ![IMages1](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2F1.png?alt=media&token=0f7b6430-7dac-453e-879f-f0523792fb31) ![alt Setting IMages2](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2F2.png?alt=media&token=a0aa40d3-2f84-4886-9579-79fdd694290d) ![alt Setting IMages3](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2F3.png?alt=media&token=412a7e86-0363-4e97-bf01-e130865d015f) ![gif1](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2Faniated_forgithub.gif?alt=media&token=d17c187f-8192-4d2f-a44e-26020acfd3eb) ![gif2](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2Fgif_for_github.gif?alt=media&token=060e72c1-a3fd-4090-8589-7e85ed598b0e) # Prerequisites - Android 16 # Installing ## Step 1:- Add it in your root build.gradle at the end of repositories: ```` all projects { repositories { ... maven { url 'https://jitpack.io' } } } ```` ## Step 2:- Add the dependency: ```` dependencies { implementation 'com.github.prabhat1707:EasyWayLocation:2.4' } ```` ### Library uses java 8 bytecode, so dont forget to enable java 8 in your application's build.gradle file. ```` android { compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } } ```` # Usage ###### If the device is running Android 6.0 or higher, and your app's target SDK is 29 or higher then first check the permission of location then call it. ## Add the required permissions For fine location (GPS location), add the following permission in your AndroidManifest.xml: ```` ```` For coarse location (network location), add the following permission in your AndroidManifest.xml: ```` ```` # Retrieve the location from the device ```` public class MainActivity extends AppCompatActivity implements Listener { EasyWayLocation easyWayLocation; private TextView location, latLong, diff; private Double lati, longi; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //-- easyWayLocation = new EasyWayLocation(this, false,false,this); } @Override public void locationOn() { Toast.makeText(this, "Location ON", Toast.LENGTH_SHORT).show(); } @Override public void currentLocation(Location location) { StringBuilder data = new StringBuilder(); data.append(location.getLatitude()); data.append(" , "); data.append(location.getLongitude()); latLong.setText(data); getLocationDetail.getAddress(location.getLatitude(), location.getLongitude(), "xyz"); } @Override public void locationCancelled() { Toast.makeText(this, "Location Cancelled", Toast.LENGTH_SHORT).show(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case LOCATION_SETTING_REQUEST_CODE: easyWayLocation.onActivityResult(resultCode); break; } } @Override protected void onResume() { super.onResume(); easyWayLocation.startLocation(); } @Override protected void onPause() { super.onPause(); easyWayLocation.endUpdates(); } } ```` # Location Notifier ```` @Override public void locationOn() { Toast.makeText(this, "Location ON", Toast.LENGTH_SHORT).show(); } @Override public void currentLocation(Location location){ // give lat and long at every interval } @Override public void locationCancelled() { // location not on } ```` # Constructor options ## Points to Remember - if you want only last location then pass it true and if false then it gives you location update as per default location request. - if you don't pass then it takes default location request or you can pass your's one also(see constructor 2nd). ```` Context context = this; boolean requireFineGranularity = false; new EasyWayLocation(this, requireLastLocation = false,isDebuggable = true/false,listner = this); or request = new LocationRequest(); request.setInterval(10000); request.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); new EasyWayLocation(this,locationRequest = request , requireLastLocation = false,isDebuggable = true/false,listner = this); ```` ## Calculate distance between two points ```` double startLatitude = 59.95; double startLongitude = 30.3; double endLatitude = 44.84; double endLongitude = -0.58; location.calculateDistance(startLatitude, startLongitude, endLatitude, endLongitude); // or Point startPoint = new EasyWayLocation.Point(59.95, 30.3); Point endPoint = new EasyWayLocation.Point(44.84, -0.58); location.calculateDistance(startPoint, endPoint); ```` ## Update Get Address Details of location. - if you want an address from the current location then you need to pass key and context. - why I want key here if android already provides Geocoder because in some cases or some devices geocoder not work well and throws Exception, so in that case, I use google geocode API for fetch address. - For this, you need to implement Callback, LocationData.AddressCallBack ```` GetLocationDetail getLocationDetail = new GetLocationDetail(callback = this, context = this); getLocationDetail.getAddress(location.getLatitude(), location.getLongitude(), key = "xyz"); ```` ## Google Map Route #### If you want to add map route feature in your apps you can use this along with this lib by adding DirectionUtil Class to make you work more easier. This is lib will help you to draw route maps between two-point LatLng along it's with waypoints. ## When Your GoogleMap Ready #### Make sure you enable google map and google map direction in the google developer console. #### First Initialize Direction Util ```` wayPoints.add(LatLng(37.423669, -122.090168)) wayPoints.add(LatLng(37.420930, -122.085362)) val directionUtil = DirectionUtil.Builder() .setDirectionKey("xyz") .setOrigin(LatLng(37.421481, -122.092156)) .setWayPoints(wayPoints) .setGoogleMap(mMap) .setPolyLinePrimaryColor(R.color.black) .setPolyLineWidth(5) .setPathAnimation(true) .setCallback(this) .setPolylineTag(WAY_POINT_TAG) .setDestination(LatLng(37.421519, -122.086809)) .build() ```` #### Add below line for route draw #### First call init and then drawRoute ```` directionUtil.initPath() directionUtil.drawPath(WAY_POINT_TAG) ```` #### Now from v2.4 you can change origin, color etc in between path ```` directionUtil.serOrigin(LatLng(driverCurrentLocation.latitude,driverCurrentLocation.longitude),wayPoints) ```` #### Add below line for Arc draw ```` directionUtil.drawArcDirection(LatLng(37.421481, -122.092156),LatLng(37.421519, -122.086809),0.5,ARC_POINT_TAG) ```` #### Add below line to remove polyline according to corresponding TAG ```` directionUtil.clearPolyline(WAY_POINT_TAG) ```` # There are two cases in it: - With Animation like Uber - without Animation. 1. With Animation - setPathAnimation = true ![gif1](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2Fanimation_route.gif?alt=media&token=97af3e8c-e302-41af-b93b-e8b85b47d9e7) 2. Without Animation - setPathAnimation = false - change its color by, setPolyLinePrimaryColor() property ![gif2](https://firebasestorage.googleapis.com/v0/b/chatapp-2e1df.appspot.com/o/location%20images%2Fnormal_routw.gif?alt=media&token=76e35316-2e76-4d4d-9099-98f3f0678b34) ## Callbacks #### When route draw path has done then it below callback is called ```` override fun pathFindFinish(polyLineDetails: HashMap) { for (i in polyLineDetails.keys){ Log.v("sample",polyLineDetails[i]?.time) } } ```` here, polyLineDetails contain each polyline or route detail as time, distance and road summary. #### You can also change the route animation different properties like delay, primary color, a secondary color, etc, just explore it. #### Bugs, Feature requests Found a bug? Something that's missing? Feedback is an important part of improving the project, so, please open an issue # License ```` Copyright (c) delight.im Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable la w or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```` ================================================ FILE: app/.gitignore ================================================ /build ================================================ FILE: app/build.gradle ================================================ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 defaultConfig { applicationId "com.example.prabhat.locationsample" minSdkVersion 17 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility = '1.8' targetCompatibility = '1.8' } buildToolsVersion = '28.0.3' } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation project(':easywaylocation') implementation 'com.google.android.gms:play-services-maps:17.0.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.google.maps.android:android-maps-utils:0.6.2' implementation 'androidx.cardview:cardview:1.0.0' } ================================================ FILE: app/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the # proguardFiles setting in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile ================================================ FILE: app/src/debug/res/values/google_maps_api.xml ================================================ xyz ================================================ FILE: app/src/main/AndroidManifest.xml ================================================ ================================================ FILE: app/src/main/java/com/example/prabhat/locationsample/CustomInfoWindowForGoogleMap.kt ================================================ package com.example.prabhat.locationsample import android.app.Activity import android.content.Context import android.view.View import android.widget.TextView import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.model.Marker import org.json.JSONObject import java.lang.Exception import java.text.DecimalFormat class CustomInfoWindowForGoogleMap(context: Context): GoogleMap.InfoWindowAdapter { private val df: DecimalFormat = DecimalFormat("0.00") var mWindow = (context as Activity).layoutInflater.inflate(R.layout.marker_window, null) override fun getInfoWindow(p0: Marker?): View { render(p0, mWindow) return mWindow } override fun getInfoContents(p0: Marker?): View { render(p0, mWindow) return mWindow } private fun render(marker: Marker?, mWindow: View) { val title = mWindow.findViewById(R.id.textView) val time = mWindow.findViewById(R.id.textView2) val distance = mWindow.findViewById(R.id.textView3) try { val json = JSONObject(marker?.title) title.text = json.getString("placeSummary") if (json.getString("time").isNotEmpty()){ time.visibility = View.VISIBLE distance.visibility = View.VISIBLE time.text = df.format(json.getString("timeFromPrevPoint").toDouble()/60) + " sec" distance.text = df.format(json.getString("distanceFromPrevPoint").toDouble()/1609.344)+" mile" }else{ time.visibility = View.GONE distance.visibility = View.GONE } }catch (e:Exception){ e.printStackTrace() } } } ================================================ FILE: app/src/main/java/com/example/prabhat/locationsample/MainActivity.java ================================================ package com.example.prabhat.locationsample; import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.os.Bundle; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import com.example.easywaylocation.EasyWayLocation; import com.example.easywaylocation.GetLocationDetail; import com.example.easywaylocation.Listener; import com.example.easywaylocation.LocationData; import static com.example.easywaylocation.EasyWayLocation.LOCATION_SETTING_REQUEST_CODE; public class MainActivity extends AppCompatActivity implements Listener, LocationData.AddressCallBack { //EasyWayLocation easyWayLocation; private TextView location, latLong, diff; private Double lati, longi; //private TestLocationRequest testLocationRequest; private EasyWayLocation easyWayLocation; GetLocationDetail getLocationDetail; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); location = findViewById(R.id.location); latLong = findViewById(R.id.latlong); diff = findViewById(R.id.diff); getLocationDetail = new GetLocationDetail(this, this); easyWayLocation = new EasyWayLocation(this, false,true,this); if (permissionIsGranted()) { doLocationWork(); } else { // Permission not granted, ask for it //testLocationRequest.requestPermission(121); } } public boolean permissionIsGranted() { int permissionState = ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION); return permissionState == PackageManager.PERMISSION_GRANTED; } private void doLocationWork() { easyWayLocation.startLocation(); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == LOCATION_SETTING_REQUEST_CODE) { easyWayLocation.onActivityResult(resultCode); } } @Override protected void onResume() { super.onResume(); easyWayLocation.startLocation(); } @Override protected void onPause() { super.onPause(); easyWayLocation.endUpdates(); } @Override public void locationOn() { Toast.makeText(this, "Location On", Toast.LENGTH_SHORT).show(); } @Override public void currentLocation(Location location) { StringBuilder data = new StringBuilder(); data.append(location.getLatitude()); data.append(" , "); data.append(location.getLongitude()); latLong.setText(data); getLocationDetail.getAddress(location.getLatitude(), location.getLongitude(), "xyz"); } @Override public void locationCancelled() { Toast.makeText(this, "Location Cancelled", Toast.LENGTH_SHORT).show(); } @Override public void locationData(LocationData locationData) { location.setText(locationData.getFull_address()); } } ================================================ FILE: app/src/main/java/com/example/prabhat/locationsample/MapsActivity.kt ================================================ package com.example.prabhat.locationsample import android.Manifest import android.animation.ValueAnimator import android.content.Intent import android.content.pm.PackageManager import android.graphics.Bitmap import android.graphics.drawable.BitmapDrawable import android.location.Location import android.os.Bundle import android.os.Handler import android.os.SystemClock import android.util.Log import android.view.View import android.view.animation.Interpolator import android.view.animation.LinearInterpolator import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import com.example.easywaylocation.EasyWayLocation import com.example.easywaylocation.Listener import com.example.easywaylocation.draw_path.DirectionUtil import com.example.easywaylocation.draw_path.PolyLineDataBean import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.OnMapReadyCallback import com.google.android.gms.maps.SupportMapFragment import com.google.android.gms.maps.model.BitmapDescriptorFactory import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.Marker import com.google.android.gms.maps.model.MarkerOptions import com.google.maps.android.SphericalUtil import kotlinx.android.synthetic.main.activity_maps.* class MapsActivity : AppCompatActivity(), OnMapReadyCallback, DirectionUtil.DirectionCallBack, Listener { private var isMarkerRotating: Boolean = false lateinit var polyLineDetails:HashMap lateinit var directionUtil: DirectionUtil lateinit var easyWayLocation: EasyWayLocation var movingCabMarker: Marker? = null lateinit var driverCurrentLocation: Location var markerList = ArrayList() companion object{ val WAY_POINT_TAG = "way_point_tag" val ARC_POINT_TAG = "arc_point_tag" val waypoint1 = LatLng(37.423669, -122.090168) val waypoint2 = LatLng(37.420930, -122.085362) val origin = LatLng(37.421481, -122.092156) val destination = LatLng(37.421519, -122.086809) val markerOptionsOrigin = MarkerOptions() val markerOptionsDestination = MarkerOptions() } override fun pathFindFinish( polyLineDetailsMap: HashMap, polyLineDetailsArray: ArrayList ) { this.polyLineDetails = polyLineDetailsMap for (marker in markerList){ marker.remove() } // animateCamera(LatLng(driverCurrentLocation.latitude,driverCurrentLocation.longitude)) animateMarker(LatLng(driverCurrentLocation.latitude,driverCurrentLocation.longitude), movingCabMarker, driverCurrentLocation.bearing) initAllMarker(polyLineDetailsArray) directionUtil.drawPath(WAY_POINT_TAG) } private fun initAllMarker(polyLineDetails: ArrayList) { markerList.clear() // markerOptionsOrigin.rotation(SphericalUtil.computeHeading(origin, waypoint1).toFloat()) for (data in polyLineDetails){ data.position?.let { val markerOptionswayPoint = MarkerOptions() markerOptionswayPoint.position(data.position!!) markerOptionswayPoint.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)); markerOptionswayPoint.title(data.toJson().toString()) markerList.add(mMap.addMarker(markerOptionswayPoint)) } } } private lateinit var mMap: GoogleMap private var wayPoints:ArrayList = ArrayList() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_maps) // Obtain the SupportMapFragment and get notified when the map is ready to be used. val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment mapFragment.getMapAsync(this) } override fun onMapReady(googleMap: GoogleMap) { mMap = googleMap val markerInfoWindowAdapter = CustomInfoWindowForGoogleMap(this) googleMap.setInfoWindowAdapter(markerInfoWindowAdapter) mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(37.423669, -122.090168), 16F)) wayPoints.add(waypoint1) wayPoints.add(waypoint2) directionUtil = DirectionUtil.Builder() .setDirectionKey("xyz") .setOrigin(origin) .setWayPoints(wayPoints) .setGoogleMap(mMap) .setPathAnimation(true) .setPolyLineWidth(5) .setCallback(this) .setDestination(destination) .build() easyWayLocation = EasyWayLocation(this, false, true, this) easyWayLocation.endUpdates() val bean = PolyLineDataBean().also { it.placeSummary = "Origin" } val bean2 = PolyLineDataBean().also { it.placeSummary = "destination" } markerOptionsOrigin.position(origin) markerOptionsOrigin.icon(BitmapDescriptorFactory.fromBitmap(getIcon(R.drawable.map_pin))); markerOptionsOrigin.title(bean.toJson().toString()) val data = directionUtil.getShortestPathDetails(origin, destination) markerOptionsDestination.position(destination) markerOptionsDestination.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin)); markerOptionsDestination.title(data.toJson().toString()) directionUtil.drawArcDirection(origin, destination, 0.5, ARC_POINT_TAG) markerList.add(mMap.addMarker(markerOptionsOrigin)) markerList.add(mMap.addMarker(markerOptionsDestination)) end_update.setOnClickListener { easyWayLocation.endUpdates() } button2.setOnClickListener { if (permissionIsGranted()) { button2.visibility = View.GONE end_update.visibility = View.VISIBLE directionUtil.clearPolyline(ARC_POINT_TAG) easyWayLocation.startLocation() } else { // Permission not granted, ask for it //testLocationRequest.requestPermission(121); } button2.text = "Complete Ride" } } fun permissionIsGranted(): Boolean { val permissionState = ActivityCompat.checkSelfPermission( this, Manifest.permission.ACCESS_FINE_LOCATION ) return permissionState == PackageManager.PERMISSION_GRANTED } fun getIcon(id:Int):Bitmap{ val height = 100 val width = 100 val bitmapdraw: BitmapDrawable = resources.getDrawable(id) as BitmapDrawable val b: Bitmap = bitmapdraw.getBitmap() return Bitmap.createScaledBitmap(b, width, height, false) } override fun locationOn() { } override fun currentLocation(location: Location?) { try { try { directionUtil.clearPolyline(WAY_POINT_TAG) }catch (e:java.lang.Exception){ e.printStackTrace() } location?.let { driverCurrentLocation = it checkPoint(driverCurrentLocation,wayPoints); if (movingCabMarker == null){ markerOptionsOrigin .icon(BitmapDescriptorFactory.fromBitmap(getIcon(R.drawable.car_icon))) .anchor(0.5f, 0.5f) .rotation(driverCurrentLocation.bearing) .flat(true) .title("Driver") movingCabMarker = mMap.addMarker(markerOptionsOrigin) } directionUtil.serOrigin( LatLng(driverCurrentLocation.latitude,driverCurrentLocation.longitude),wayPoints) directionUtil.initPath() } }catch (e:Exception){ e.printStackTrace() } } fun animateCamera(location: LatLng) { mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, mMap.cameraPosition.zoom)) } private fun checkPoint(location: Location, wayPoints: ArrayList) { val results = FloatArray(1) for (points in wayPoints){ Location.distanceBetween( location.latitude, location.longitude, points.latitude, points.longitude, results ) val distanceInMeters = results[0] if(distanceInMeters <= 50.0){ wayPoints.remove(points) } return } } override fun locationCancelled() { } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == EasyWayLocation.LOCATION_SETTING_REQUEST_CODE) { easyWayLocation.onActivityResult(resultCode) } } private fun rotateMarker(marker: Marker, toRotation: Float) { if (!isMarkerRotating) { val handler = Handler() val start: Long = SystemClock.uptimeMillis() val startRotation = marker.rotation val duration: Long = 1000 val interpolator: Interpolator = LinearInterpolator() handler.post(object : Runnable { override fun run() { isMarkerRotating = true val elapsed: Long = SystemClock.uptimeMillis() - start val t: Float = interpolator.getInterpolation(elapsed.toFloat() / duration) val rot = t * toRotation + (1 - t) * startRotation marker.rotation = if (-rot > 180) rot / 2 else rot if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16) } else { isMarkerRotating = false } } }) } } private fun animateMarker(destination: LatLng, marker: Marker?, bearing: Float) { if (marker != null) { Log.d("check_in_device_9", "----------->" + "markerAnimate" + destination.latitude.toString()) val startPosition = marker.position val startRotation = marker.rotation val latLngInterpolator = LatLngInterpolator.LinearFixed() val valueAnimator = ValueAnimator.ofFloat(0F, 1F) valueAnimator.duration = 1000 // duration 1 second valueAnimator.interpolator = LinearInterpolator() valueAnimator.addUpdateListener { try { val v = it.animatedFraction val newPosition = latLngInterpolator.interpolate(v, startPosition, destination) marker.position = newPosition marker.setAnchor(0.5f, 0.5f) marker.rotation = computeRotation(v, startRotation, bearing) marker.isFlat = true } catch (ex: Exception) { ex.printStackTrace() Log.d("check_in_device_9", "----------->" + "exsception" + ex.message.toString()) } } valueAnimator.start() } } fun computeRotation(fraction: Float, start: Float, end: Float): Float { val normalizeEnd = end - start // rotate start to 0 val normalizedEndAbs = (normalizeEnd + 360) % 360 val direction: Float if (normalizedEndAbs > 180) { direction = -1F } else { direction = 1F } // val direction: Float = (normalizedEndAbs > 180) ?-1 : 1; // -1 = anticlockwise, 1 = clockwise val rotation: Float if (direction > 0) { rotation = normalizedEndAbs } else { rotation = normalizedEndAbs - 360 } val result = fraction * rotation + start return (result + 360) % 360 } interface LatLngInterpolator { fun interpolate(fraction: Float, a: LatLng, b: LatLng): LatLng class LinearFixed : LatLngInterpolator { override fun interpolate(fraction: Float, a: LatLng, b: LatLng): LatLng { val lat = (b.latitude - a.latitude) * fraction + a.latitude var lngDelta = b.longitude - a.longitude // Take the shortest path across the 180th meridian. if (Math.abs(lngDelta) > 180) { lngDelta -= Math.signum(lngDelta) * 360 } val lng = lngDelta * fraction + a.longitude return LatLng(lat, lng) } } } } ================================================ FILE: app/src/main/res/drawable/ic_launcher_background.xml ================================================ ================================================ FILE: app/src/main/res/drawable-v24/ic_launcher_foreground.xml ================================================ ================================================ FILE: app/src/main/res/layout/activity_main.xml ================================================ ================================================ FILE: app/src/main/res/layout/activity_maps.xml ================================================