MapApiDemo.rar
大小:1.98MB
价格:19积分
下载量:0
评分:
5.0
上传者:rowangame
更新日期:2025-09-22

android 百度地图 定位示例

资源文件列表(大概)

文件名
大小
MapApiDemo\.classpath
185B
MapApiDemo\.project
277B
MapApiDemo\AndroidManifest.xml
730B
MapApiDemo\bin\AndroidManifest.xml
730B
MapApiDemo\bin\classes\com\obtk\mapdemo\BuildConfig.class
272B
MapApiDemo\bin\classes\com\obtk\mapdemo\MapApiDemoActivity$1.class
582B
MapApiDemo\bin\classes\com\obtk\mapdemo\MapApiDemoActivity$MyLocationListenner.class
1.54KB
MapApiDemo\bin\classes\com\obtk\mapdemo\MapApiDemoActivity.class
2.63KB
MapApiDemo\bin\classes\com\obtk\mapdemo\R$attr.class
262B
MapApiDemo\bin\classes\com\obtk\mapdemo\R$drawable.class
307B
MapApiDemo\bin\classes\com\obtk\mapdemo\R$id.class
336B
MapApiDemo\bin\classes\com\obtk\mapdemo\R$layout.class
306B
MapApiDemo\bin\classes\com\obtk\mapdemo\R$menu.class
306B
MapApiDemo\bin\classes\com\obtk\mapdemo\R$string.class
342B
MapApiDemo\bin\classes\com\obtk\mapdemo\R$style.class
322B
MapApiDemo\bin\classes\com\obtk\mapdemo\R.class
359B
MapApiDemo\gen\com\obtk\mapdemo\BuildConfig.java
142B
MapApiDemo\gen\com\obtk\mapdemo\R.java
699B
MapApiDemo\ic_launcher-web.png
51.01KB
MapApiDemo\libs\android-support-v4.jar
322.3KB
MapApiDemo\libs\armeabi\libBaiduMapSDK_v3_4_0_15.so
685.38KB
MapApiDemo\libs\armeabi\liblocSDK5.so
18.16KB
MapApiDemo\libs\baidumapapi_v3_4_0.jar
717.49KB
MapApiDemo\libs\locSDK_5.0.jar
190.98KB
MapApiDemo\proguard-project.txt
460B
MapApiDemo\project.properties
382B
MapApiDemo\res\drawable-hdpi\ic_launcher.png
8.02KB
MapApiDemo\res\drawable-ldpi\ic_launcher.png
2.5KB
MapApiDemo\res\drawable-mdpi\ic_launcher.png
3.97KB
MapApiDemo\res\drawable-xhdpi\ic_launcher.png
13.25KB
MapApiDemo\res\layout\activity_map_api_demo.xml
369B
MapApiDemo\res\menu\activity_map_api_demo.xml
167B
MapApiDemo\res\values\strings.xml
154B
MapApiDemo\res\values\styles.xml
338B
MapApiDemo\res\values-v11\styles.xml
221B
MapApiDemo\res\values-v14\styles.xml
252B
MapApiDemo\src\com\obtk\mapdemo\MapApiDemoActivity.java
2.19KB
MapApiDemo\bin\classes\com\obtk\mapdemo
-
MapApiDemo\bin\classes\com\obtk
-
MapApiDemo\gen\com\obtk\mapdemo
-
MapApiDemo\src\com\obtk\mapdemo
-
MapApiDemo\bin\classes\com
-
MapApiDemo\gen\com\obtk
-
MapApiDemo\src\com\obtk
-
MapApiDemo\bin\classes
-
MapApiDemo\bin\res
-
MapApiDemo\gen\com
-
MapApiDemo\libs\armeabi
-
MapApiDemo\res\drawable-hdpi
-
MapApiDemo\res\drawable-ldpi
-
MapApiDemo\res\drawable-mdpi
-
MapApiDemo\res\drawable-xhdpi
-
MapApiDemo\res\layout
-
MapApiDemo\res\menu
-
MapApiDemo\res\values
-
MapApiDemo\res\values-v11
-
MapApiDemo\res\values-v14
-
MapApiDemo\src\com
-
MapApiDemo\assets
-
MapApiDemo\bin
-
MapApiDemo\gen
-
MapApiDemo\libs
-
MapApiDemo\res
-
MapApiDemo\src
-
MapApiDemo
-

资源内容介绍

1.需要在 http://developer.baidu.com/ 注册开发者(个人或公司)账号 2.需要申请Key 打开网址 http://developer.baidu.com/map/index.php 点击 创建应用,跟流程创建应用app3.点击相关下载->一键下载4.调用百度地图的APP 需要在 AndroidManifest.xml 添加 这里需要添加key,创建应用后,会有这个key ..... package com.obtk.mapdemo;import com.baidu.location.BDLocation;import com.baidu.location.BDLocationListener;import com.baidu.location.LocationClient;import com.baidu.location.LocationClientOption;import com.baidu.mapapi.SDKInitializer;import com.baidu.mapapi.map.BaiduMap;import com.baidu.mapapi.map.BaiduMapOptions;import com.baidu.mapapi.map.MapStatusUpdate;import com.baidu.mapapi.map.MapStatusUpdateFactory;import com.baidu.mapapi.map.MapView;import com.baidu.mapapi.map.MyLocationData;import com.baidu.mapapi.map.MyLocationConfiguration.LocationMode;import com.baidu.mapapi.model.LatLng;import com.baidu.mapapi.search.core.SearchResult;import com.baidu.mapapi.search.geocode.GeoCodeResult;import com.baidu.mapapi.search.geocode.GeoCoder;import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;import com.baidu.mapapi.search.geocode.ReverseGeoCodeOption;import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;import android.os.Bundle;import android.util.Log;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.RelativeLayout;import android.widget.Toast;import android.app.Activity;import com.obtk.mapdemo.R;public class MapApiDemoActivity extends Activity implements OnGetGeoCoderResultListener {private MapView mMapView = null;private BaiduMap mBaiduMap = null;private GeoCoder mSearch = null; @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// SDK初始化SDKInitializer.initialize(getApplicationContext());//当前视图setContentView(R.layout.activity_map_api_demo);//创建地图对象init();final Button btn_location = (Button) findViewById(R.id.btn_location);btn_location.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubgetLocation();btn_location.setEnabled(false);}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.activity_map_api_demo, menu);return true;}/** * 初始化方法 */private void init() {//mMapView = (MapView) findViewById(R.id.bmapview);mMapView = new MapView(this, new BaiduMapOptions());mBaiduMap = mMapView.getMap();/**添加一个对象*/RelativeLayout rlly_map = (RelativeLayout)findViewById(R.id.rlly_map);rlly_map.addView(mMapView);// 开启定位图层 mBaiduMap.setMyLocationEnabled(true); //初始化搜索模块,注册事件监听 mSearch = GeoCoder.newInstance(); mSearch.setOnGetGeoCodeResultListener(this);}@Overrideprotected void onResume() {super.onResume();mMapView.onResume();}@Overrideprotected void onPause() {super.onPause();mMapView.onPause();}@Overrideprotected void onDestroy() {// 退出时销毁定位mLocClient.stop();// 关闭定位图层mBaiduMap.setMyLocationEnabled(false);mMapView.onDestroy();mMapView = null;super.onDestroy();}// 定位相关LocationClient mLocClient;public MyLocationListenner myListener = new MyLocationListenner();private LocationMode mCurrentMode;private boolean isFirstLoc = true;/** * 定位SDK监听函数 */public class MyLocationListenner implements BDLocationListener {@Overridepublic void onReceiveLocation(BDLocation location) {// map view 销毁后不在处理新接收的位置if (location == null || mMapView == null)return;MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())//此处设置开发者获取到的方向信息,顺时针0-360.direction(100).latitude(location.getLatitude()).longitude(location.getLongitude()).build();mBaiduMap.setMyLocationData(locData);if (isFirstLoc) {isFirstLoc = false;LatLng ll = new LatLng(location.getLatitude(),location.getLongitude());MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);mBaiduMap.animateMapStatus(u);}String addr = location.getAddrStr();if (addr != null) {Log.i("Test", addr);} else {Log.i("Test","error");}double longitude = location.getLongitude();double latitude = location.getLatitude();if (longitude > 0 && latitude > 0) {Log.i("Test",String.format("纬度:%f 经度:%f", latitude,longitude));LatLng ptCenter = new LatLng(latitude,longitude);// 反Geo搜索mSearch.reverseGeoCode(new ReverseGeoCodeOption().location(ptCenter));} //停止定位mLocClient.stop();}public void onReceivePoi(BDLocation poiLocation) {}}private void getLocation() {// 定位初始化mLocClient = new LocationClient(this);mLocClient.registerLocationListener(myListener);LocationClientOption option = new LocationClientOption();option.setOpenGps(true);//打开gpsoption.setCoorType("bd09ll"); //设置坐标类型option.setScanSpan(5000); //定位时间间隔mLocClient.setLocOption(option);mLocClient.start();}@Overridepublic void onGetGeoCodeResult(GeoCodeResult arg0) {// TODO Auto-generated method stub}@Overridepublic void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {// TODO Auto-generated method stubif (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {Toast.makeText(MapApiDemoActivity.this,"抱歉,未能找到结果", Toast.LENGTH_LONG).show();return;}mBaiduMap.clear();//mBaiduMap.addOverlay(new MarkerOptions().position(result.getLocation())//.icon(BitmapDescriptorFactory//.fromResource(R.drawable.icon_marka)));mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(result.getLocation()));Toast.makeText(MapApiDemoActivity.this, result.getAddress(),Toast.LENGTH_LONG).show();String province = result.getAddressDetail().province;String city = result.getAddressDetail().city;if (province != null && city != null) {}}}
# To enable ProGuard in your project, edit project.properties# to define the proguard.config property as described in that file.## Add project specific ProGuard rules here.# By default, the flags in this file are appended to flags specified# in ${sdk.dir}/tools/proguard/proguard-android.txt# You can edit the include path and order by changing the ProGuard# include property in project.properties.## For more details, see# http://developer.android.com/guide/developing/tools/proguard.html# Add any project specific keep options here:# 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 *;#}

用户评论 (0)

发表评论

captcha