首页 > 代码库 > android百度定位后显示在地图上点击弹出气泡
android百度定位后显示在地图上点击弹出气泡
1.到百度地图页面申请key,注意key和项目包名和数字签名一一对应的。http://developer.baidu.com/map/index.php?title=%E9%A6%96%E9%A1%B5
2.下载相应的sdk包 :http://lbsyun.baidu.com/sdk/download
3. 创建项目,加入相应的包
在AndroidManifest中添加开发密钥、所需权限等信息;
(1)在application中添加开发密钥
<application <meta-data android:name="com.baidu.lbsapi.API_KEY" android:value="开发者 key" />
<service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote" > </service></application>
2)添加所需权限
<permission android:name="android.permission.BAIDU_LOCATION_SERVICE" > </permission> <uses-permission android:name="android.permission.BAIDU_LOCATION_SERVICE" > </uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" > </uses-permission> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" > </uses-permission> <uses-permission android:name="android.permission.INTERNET" > </uses-permission> <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" > </uses-permission> <!-- <uses-permission android:name="android.permission.WRITE_APN_SETTINGS"></uses-permission> --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" > </uses-permission> <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" /> <uses-permission android:name="android.permission.WAKE_LOCK" > </uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_GPS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.SEND_SMS" /> <!-- SDK1.5需要android.permission.GET_TASKS权限判断本程序是否为当前运行的应用? --> <uses-permission android:name="android.permission.GET_TASKS" /> <uses-permission android:name="android.permission.CAMERA" > </uses-permission> <uses-permission android:name="android.permission.RECORD_AUDIO" > </uses-permission> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" > </uses-permission> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.BROADCAST_STICKY" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <!-- 来电消音 --> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" > </uses-permission> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
第三步,添加布局文件 ,代码里面使用该LinearLayout把mapview添加上来
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:id="@+id/map"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > </LinearLayout>
</RelativeLayout>
还可以这样:
<com.baidu.mapapi.map.MapView android:id="@+id/bmapView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" />第一种我们可以在代码设置一些配置信息,比如去掉缩放控件
主要代码:
<script src="https://code.csdn.net/snippets/473609.js" type="text/javascript"></script>效果图
完整demo:
android百度定位后显示在地图上点击弹出气泡