├── .gitignore ├── .idea ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ └── output.json └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── sinfeeloo │ │ └── openmapdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── sinfeeloo │ │ │ └── openmapdemo │ │ │ ├── InputTipsActivity.java │ │ │ ├── InputTipsAdapter.java │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── back.xml │ │ ├── ic_launcher_background.xml │ │ └── title_background.9.png │ │ ├── layout │ │ ├── activity_input_tips.xml │ │ ├── activity_main.xml │ │ └── adapter_inputtips.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_arrow_back.png │ │ ├── ic_close.png │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── ic_search.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── ic_search.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── ic_search.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_round.png │ │ └── ic_search.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── sinfeeloo │ └── openmapdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── openmap ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── sinfeeloo │ │ └── openmap │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── sinfeeloo │ │ │ └── openmap │ │ │ ├── App.java │ │ │ ├── AppUtils.java │ │ │ ├── CoodinateCovertor.java │ │ │ ├── LngLat.java │ │ │ ├── OpenMapUtil.java │ │ │ └── ToastUtils.java │ └── res │ │ ├── anim │ │ ├── hide_popupwindow.xml │ │ └── show_popupwindow.xml │ │ ├── layout │ │ └── popu_open_map.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── sinfeeloo │ └── openmap │ └── ExampleUnitTest.java ├── screenshot ├── pic1.jpg ├── pic2.jpg ├── pic3.jpg └── pic4.jpg └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | 43 | # Keystore files 44 | *.jks 45 | 46 | # External native build folder generated in Android Studio 2.2 and later 47 | .externalNativeBuild 48 | 49 | # Google Services (e.g. APIs or Firebase) 50 | google-services.json 51 | 52 | # Freeline 53 | freeline.py 54 | freeline/ 55 | freeline_project_description.json 56 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | C:\Users\mhjdx\AppData\Roaming\Subversion 35 | 36 | 37 | 38 | 39 | 40 | 1.8 41 | 42 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenMapDemo 2 | 3 | 从应用内打开百度、高德、腾讯地图app 4 | 5 | ## 原理 ## 6 | - 通过高德、百度、腾讯提供的Uri打开应用外部地图app. 7 | 8 | ## 高德、百度、腾讯官方uri调起app文档传送门## 9 | - [高德地图:http://lbs.amap.com/api/amap-mobile/guide/android/route](http://lbs.amap.com/api/amap-mobile/guide/android/route) 10 | - [百度地图:http://lbsyun.baidu.com/index.php?title=uri/api/android](http://lbsyun.baidu.com/index.php?title=uri/api/android) 11 | - [腾讯地图:http://lbs.qq.com/uri_v1/index.html](http://lbs.qq.com/uri_v1/index.html) 12 | 13 | ## 关键代码 ## 14 | -以高德地图为例: 15 | ``` 16 | /** 17 | * 打开高德 18 | * 19 | * @param latitude 20 | * @param longitude 21 | */ 22 | private static void openGaode(Activity activity, String title, double latitude, double longitude) { 23 | if (AppUtils.isAvilible("com.autonavi.minimap")) { 24 | Intent intent = new Intent(); 25 | intent.setAction(Intent.ACTION_VIEW); 26 | intent.addCategory(Intent.CATEGORY_DEFAULT); 27 | 28 | //将功能Scheme以URI的方式传入data 29 | Uri uri = Uri.parse("androidamap://route/plan/?dlat=" + latitude + "&dlon=" + longitude + "&dname=" + title + "&dev=0&t=0"); 30 | intent.setData(uri); 31 | 32 | //启动该页面即可 33 | activity.startActivity(intent); 34 | } else { 35 | ToastUtils.showToast("您尚未安装高德地图"); 36 | Uri uri = Uri.parse("market://details?id=com.autonavi.minimap"); 37 | Intent intent = new Intent(Intent.ACTION_VIEW, uri); 38 | if (intent.resolveActivity(activity.getPackageManager()) != null) { 39 | activity.startActivity(intent); 40 | } 41 | } 42 | } 43 | ``` 44 | 45 | ## 需要注意的地方 ## 46 | -1.由于自己应用中集成的是高德地图,用的是GCJ-02坐标系(火星坐标系),所以当打开百度地图时需要进行坐标转换,将火星坐标系转换成百度坐标系BD09。 47 | 具体看代码: [CoodinateCovertor.java](https://github.com/lintianlin/OpenMapDemo/blob/master/openmap/src/main/java/com/sinfeeloo/openmap/CoodinateCovertor.java) 48 | 49 | ## 使用方法 ## 50 | -1.Add it in your root build.gradle at the end of repositories: 51 | ``` 52 | allprojects { 53 | repositories { 54 | ... 55 | maven { url 'https://jitpack.io' } 56 | } 57 | } 58 | ``` 59 | -2.Add the dependency 60 | ``` 61 | dependencies { 62 | compile 'com.github.lintianlin:OpenMapDemo:v1.0.0' 63 | } 64 | ``` 65 | ## 示例效果 ## 66 | 67 | 68 | 69 | 70 | 71 | 72 | # License 73 | Copyright 2018 SinFeeLoo 74 | 75 | Licensed under the Apache License, Version 2.0 (the "License"); 76 | you may not use this file except in compliance with the License. 77 | You may obtain a copy of the License at 78 | 79 | http://www.apache.org/licenses/LICENSE-2.0 80 | 81 | Unless required by applicable law or agreed to in writing, software 82 | distributed under the License is distributed on an "AS IS" BASIS, 83 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 84 | See the License for the specific language governing permissions and 85 | limitations under the License. -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.sinfeeloo.openmapdemo" 7 | minSdkVersion 19 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:26.1.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 28 | compile 'com.amap.api:location:latest.integration' 29 | compile 'com.amap.api:search:latest.integration' 30 | implementation project(':openmap') 31 | } 32 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.sinfeeloo.openmapdemo","split":"","minSdkVersion":"19"}}] -------------------------------------------------------------------------------- /app/src/androidTest/java/com/sinfeeloo/openmapdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.sinfeeloo.openmapdemo; 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 | * Instrumented 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.sinfeeloo.openmapdemo", 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 | 35 | 36 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/sinfeeloo/openmapdemo/InputTipsActivity.java: -------------------------------------------------------------------------------- 1 | package com.sinfeeloo.openmapdemo; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.widget.SearchView; 7 | import android.util.Log; 8 | import android.view.View; 9 | import android.widget.AdapterView; 10 | import android.widget.AdapterView.OnItemClickListener; 11 | import android.widget.ImageView; 12 | import android.widget.ListView; 13 | 14 | import com.amap.api.services.help.Inputtips; 15 | import com.amap.api.services.help.InputtipsQuery; 16 | import com.amap.api.services.help.Tip; 17 | 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | public class InputTipsActivity extends Activity implements SearchView.OnQueryTextListener, Inputtips.InputtipsListener, OnItemClickListener, View.OnClickListener { 23 | private SearchView mSearchView;// 输入搜索关键字 24 | private ImageView mBack; 25 | private ListView mInputListView; 26 | private List mCurrentTipList; 27 | private InputTipsAdapter mIntipAdapter; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_input_tips); 33 | initSearchView(); 34 | mInputListView = (ListView) findViewById(R.id.inputtip_list); 35 | mInputListView.setOnItemClickListener(this); 36 | mBack = (ImageView) findViewById(R.id.back); 37 | mBack.setOnClickListener(this); 38 | } 39 | 40 | private void initSearchView() { 41 | mSearchView = (SearchView) findViewById(R.id.keyWord); 42 | mSearchView.setOnQueryTextListener(this); 43 | //设置SearchView默认为展开显示 44 | mSearchView.setIconified(false); 45 | mSearchView.onActionViewExpanded(); 46 | mSearchView.setIconifiedByDefault(true); 47 | mSearchView.setSubmitButtonEnabled(false); 48 | } 49 | 50 | /** 51 | * 输入提示回调 52 | * 53 | * @param tipList 54 | * @param rCode 55 | */ 56 | @Override 57 | public void onGetInputtips(List tipList, int rCode) { 58 | if (rCode == 1000) {// 正确返回 59 | mCurrentTipList = tipList; 60 | List listString = new ArrayList(); 61 | for (int i = 0; i < tipList.size(); i++) { 62 | listString.add(tipList.get(i).getName()); 63 | } 64 | mIntipAdapter = new InputTipsAdapter( 65 | getApplicationContext(), 66 | mCurrentTipList); 67 | mInputListView.setAdapter(mIntipAdapter); 68 | mIntipAdapter.notifyDataSetChanged(); 69 | } else { 70 | Log.e("mhj", "错误:" + rCode); 71 | } 72 | 73 | } 74 | 75 | @Override 76 | public void onItemClick(AdapterView adapterView, View view, int i, long l) { 77 | if (mCurrentTipList != null) { 78 | Tip tip = (Tip) adapterView.getItemAtPosition(i); 79 | Intent intent = new Intent(); 80 | intent.putExtra("EXTRA_TIP", tip); 81 | setResult(101, intent); 82 | this.finish(); 83 | } 84 | } 85 | 86 | /** 87 | * 按下确认键触发,本例为键盘回车或搜索键 88 | * 89 | * @param query 90 | * @return 91 | */ 92 | @Override 93 | public boolean onQueryTextSubmit(String query) { 94 | return false; 95 | } 96 | 97 | /** 98 | * 输入字符变化时触发 99 | * 100 | * @param newText 101 | * @return 102 | */ 103 | @Override 104 | public boolean onQueryTextChange(String newText) { 105 | if (!IsEmptyOrNullString(newText)) { 106 | InputtipsQuery inputquery = new InputtipsQuery(newText, ""); 107 | Inputtips inputTips = new Inputtips(InputTipsActivity.this.getApplicationContext(), inputquery); 108 | inputTips.setInputtipsListener(this); 109 | inputTips.requestInputtipsAsyn(); 110 | } else { 111 | if (mIntipAdapter != null && mCurrentTipList != null) { 112 | mCurrentTipList.clear(); 113 | mIntipAdapter.notifyDataSetChanged(); 114 | } 115 | } 116 | return false; 117 | } 118 | 119 | @Override 120 | public void onClick(View view) { 121 | if (view.getId() == R.id.back) { 122 | this.finish(); 123 | } 124 | } 125 | 126 | public static boolean IsEmptyOrNullString(String s) { 127 | return (s == null) || (s.trim().length() == 0); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/sinfeeloo/openmapdemo/InputTipsAdapter.java: -------------------------------------------------------------------------------- 1 | package com.sinfeeloo.openmapdemo; 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.amap.api.services.help.Tip; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * 输入提示adapter,展示item名称和地址 16 | */ 17 | public class InputTipsAdapter extends BaseAdapter { 18 | private Context mContext; 19 | private List mListTips; 20 | 21 | public InputTipsAdapter(Context context, List tipList) { 22 | mContext = context; 23 | mListTips = tipList; 24 | } 25 | 26 | @Override 27 | public int getCount() { 28 | if (mListTips != null) { 29 | return mListTips.size(); 30 | } 31 | return 0; 32 | } 33 | 34 | 35 | @Override 36 | public Object getItem(int i) { 37 | if (mListTips != null) { 38 | return mListTips.get(i); 39 | } 40 | return null; 41 | } 42 | 43 | @Override 44 | public long getItemId(int i) { 45 | return i; 46 | } 47 | 48 | @Override 49 | public View getView(int i, View view, ViewGroup viewGroup) { 50 | Holder holder; 51 | if (view == null) { 52 | holder = new Holder(); 53 | view = LayoutInflater.from(mContext).inflate(R.layout.adapter_inputtips, null); 54 | holder.mName = (TextView) view.findViewById(R.id.name); 55 | holder.mAddress = (TextView) view.findViewById(R.id.adress); 56 | view.setTag(holder); 57 | } else{ 58 | holder = (Holder)view.getTag(); 59 | } 60 | if(mListTips == null){ 61 | return view; 62 | } 63 | 64 | holder.mName.setText(mListTips.get(i).getName()); 65 | String address = mListTips.get(i).getAddress(); 66 | if(address == null || address.equals("")){ 67 | holder.mAddress.setVisibility(View.GONE); 68 | }else{ 69 | holder.mAddress.setVisibility(View.VISIBLE); 70 | holder.mAddress.setText(address); 71 | } 72 | 73 | return view; 74 | } 75 | 76 | class Holder { 77 | TextView mName; 78 | TextView mAddress; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/java/com/sinfeeloo/openmapdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.sinfeeloo.openmapdemo; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.LinearLayout; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | import com.amap.api.services.help.Tip; 12 | import com.sinfeeloo.openmap.OpenMapUtil; 13 | 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | 17 | private TextView address; 18 | private TextView lan; 19 | private TextView lon; 20 | private TextView searchText; 21 | private TextView name; 22 | private double mLatitude; 23 | private double mLongitude; 24 | private String mName; 25 | private LinearLayout root; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main); 31 | 32 | searchText = findViewById(R.id.tv_search); 33 | name = findViewById(R.id.tv_name); 34 | address = findViewById(R.id.tv_address); 35 | lan = findViewById(R.id.tv_lan); 36 | lon = findViewById(R.id.tv_lon); 37 | root = findViewById(R.id.ll_root); 38 | 39 | 40 | searchText.setOnClickListener(new View.OnClickListener() { 41 | @Override 42 | public void onClick(View v) { 43 | Intent intent = new Intent(MainActivity.this, InputTipsActivity.class); 44 | startActivityForResult(intent, 1); 45 | } 46 | }); 47 | 48 | findViewById(R.id.btn_open).setOnClickListener(new View.OnClickListener() { 49 | @Override 50 | public void onClick(View v) { 51 | OpenMapUtil.openMapPopupWindow(MainActivity.this, root, mName, mLatitude, mLongitude); 52 | } 53 | }); 54 | } 55 | 56 | 57 | @Override 58 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 59 | super.onActivityResult(requestCode, resultCode, data); 60 | if (resultCode == 101 && data != null) { 61 | Tip tip = data.getParcelableExtra("EXTRA_TIP"); 62 | if (tip.getPoiID() != null && !tip.getPoiID().equals("")) { 63 | name.setText("名称:" + tip.getName()); 64 | address.setText("地址:" + tip.getAddress()); 65 | lan.setText("纬度:" + tip.getPoint().getLatitude()); 66 | lon.setText("经度:" + tip.getPoint().getLongitude()); 67 | mLatitude = tip.getPoint().getLatitude(); 68 | mLongitude = tip.getPoint().getLongitude(); 69 | mName = tip.getName(); 70 | } 71 | 72 | } else if (resultCode == 102 && data != null) { 73 | String keywords = data.getStringExtra("KEY_WORDS_NAME"); 74 | if (keywords != null && !keywords.equals("")) { 75 | Toast.makeText(this, keywords, Toast.LENGTH_SHORT).show(); 76 | } 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/back.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/title_background.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lintianlin/OpenMapDemo/b03e74f59903c36df450753e2fed6cde8b223407/app/src/main/res/drawable/title_background.9.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_input_tips.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 27 | 28 | 40 | 41 | 42 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 21 | 22 | 27 | 28 | 33 | 34 | 39 | 40 | 45 | 46 |