zoukankan      html  css  js  c++  java
  • 刚学会百度地图最新版的sdk,总结一个简单的demo

    <service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote" 
        android:permission="android.permission.BAIDU_LOCATION_SERVICE">
        <intent-filter>
            <action android:name="com.baidu.location.service_v2.4"></action>
        </intent-filter>
    </service>

    以上是版本区别部分。

    <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_COARSE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
    <uses-permission android:name="android.permission.READ_LOGS"></uses-permission>

    以上是权限部分

    然后就是demo的java部分

    package com.xmb.baiduloctest2;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.support.v4.app.NavUtils;
    import com.baidu.location.BDLocation;
    import com.baidu.location.BDLocationListener;
    import com.baidu.location.LocationClient;
    import com.baidu.location.LocationClientOption;
    public class MainActivity extends Activity {
        public LocationClient mLocationClient = null;
        public BDLocationListener myListener = new MyLocationListenner();
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mLocationClient = new LocationClient(this);     //声明LocationClient类
            
            LocationClientOption option = new LocationClientOption();
            option.setOpenGps(true);
            option.setAddrType("detail");
            option.setCoorType("bd09ll");
            option.setScanSpan(5000);
            option.disableCache(true);//禁止启用缓存定位
            option.setPoiNumber(5); //最多返回POI个数 
            option.setPoiDistance(1000); //poi查询距离  
            option.setPoiExtraInfo(true); //是否需要POI的电话和地址等详细信息  
            mLocationClient.setLocOption(option);
            
            mLocationClient.registerLocationListener( myListener );    //注册监听函数
            mLocationClient.start();
            
        }
        
        @Override
           public void onDestroy() {
            mLocationClient.stop();
               super.onDestroy();
           }
    
        /**
         * 监听函数,又新位置的时候,格式化成字符串,输出到屏幕中
         */
        public class MyLocationListenner implements BDLocationListener {
            @Override
            public void onReceiveLocation(BDLocation location) {
                if (location == null)
                    return ;
                StringBuffer sb = new StringBuffer(256);
                sb.append("time : ");
                sb.append(location.getTime());
                sb.append("\nerror code : ");
                sb.append(location.getLocType());
                sb.append("\nlatitude : ");
                sb.append(location.getLatitude());
                sb.append("\nlontitude : ");
                sb.append(location.getLongitude());
                sb.append("\nradius : ");
                sb.append(location.getRadius());
                if (location.getLocType() == BDLocation.TypeGpsLocation){
                    sb.append("\nspeed : ");
                    sb.append(location.getSpeed());
                    sb.append("\nsatellite : ");
                    sb.append(location.getSatelliteNumber());
                } else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
                    sb.append("\n省:");
                    sb.append(location.getProvince());
                    sb.append("\n市:");
                    sb.append(location.getCity());
                    sb.append("\n区/县:");
                    sb.append(location.getDistrict());
                    sb.append("\naddr : ");
                    sb.append(location.getAddrStr());
                }
                sb.append("\nsdk version : ");
                sb.append(mLocationClient.getVersion());
                sb.append("\nisCellChangeFlag : ");
                sb.append(location.isCellChangeFlag());
                Log.i("out","onReceiveLocation="+sb.toString());
            }
            
            public void onReceivePoi(BDLocation poiLocation) {
                if (poiLocation == null){
                    return ; 
                }
                StringBuffer sb = new StringBuffer(256);
                sb.append("Poi time : ");
                sb.append(poiLocation.getTime());
                sb.append("\nerror code : "); 
                sb.append(poiLocation.getLocType());
                sb.append("\nlatitude : ");
                sb.append(poiLocation.getLatitude());
                sb.append("\nlontitude : ");
                sb.append(poiLocation.getLongitude());
                sb.append("\nradius : ");
                sb.append(poiLocation.getRadius());
                if (poiLocation.getLocType() == BDLocation.TypeNetWorkLocation){
                    sb.append("\naddr : ");
                    sb.append(poiLocation.getAddrStr());
                } 
                if(poiLocation.hasPoi()){
                    sb.append("\nPoi:");
                    sb.append(poiLocation.getPoi());
                }else{                
                    sb.append("noPoi information");
                }
                Log.i("out","onReceivePoi="+sb.toString());
            }
        }
    }
  • 相关阅读:
    WinForm窗口间传值
    如何自定义标签
    oracle数据库开启的时候 是先开监听还是先开主服务,关数据库的时候呢???
    oracle 10g 安装时字符集的选择,和后边的修改
    Oracle数据库安装及配置(一)
    Win7下完全卸载Oracle 11g的步骤
    Oracle创建表空间、创建用户以及授权
    ORACLE创建表空间、创建用户、更改用户默认表空间以及授权、查看权限
    Linux 常用命令集合
    Java之JSP和Servlet基础知识
  • 原文地址:https://www.cnblogs.com/xmb7/p/2997839.html
Copyright © 2011-2022 走看看