android location lbs baidu 定位 划线

简介:               需要精确 定位 及划线 算法 ~~~ 求 大神 搭救 ---                   package com.curiousby.

 

 

 

 

 

 

 

需要精确 定位 及划线 算法 ~~~ 求 大神 搭救 ---

 



 

 

 

 

 

 

 

 

package com.curiousby.demo.running;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

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.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.Polyline;
import com.baidu.mapapi.map.PolylineOptions;
import com.baidu.mapapi.map.MyLocationConfiguration.LocationMode;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.model.LatLng; 
import com.curiousby.demo.BaiduLBSUtil;
import com.curiousby.demo.R; 

public class RunningMainFragment extends Fragment {

	// 定位相关
    LocationClient mLocClient;
    public MyLocationListenner myListener = new MyLocationListenner();
	MapView mMapView = null; 
	BaiduMap mBaiduMap;
	
	private LocationMode mCurrentMode;
	//BitmapDescriptor mCurrentMarker;
	private View mBaseView;
	Polyline mPolyline;
	Polyline mColorfulPolyline;
	Polyline mTexturePolyline;
	 boolean isFirstLoc = true; // 是否首次定位
	  private static final int accuracyCircleFillColor = 0xAAFFFF88;
	    private static final int accuracyCircleStrokeColor = 0xAA00FF00;
	static BitmapDescriptor mGreenTexture ;
	 
	private double mLatitude;
	private double mLongitude; 
	private long mTime;
	
	private double currentLatitude;
	private double currentLongitude;
	private long currentTime;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		SDKInitializer.initialize(getActivity().getApplicationContext());
		 mCurrentMode = LocationMode.FOLLOWING;
		//mCurrentMarker = BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher);
		 mGreenTexture = BitmapDescriptorFactory.fromAsset("icon_road_green_arrow.png");
        mBaseView =  LayoutInflater.from(getActivity()).inflate(R.layout.running_tab_main,null);
		mMapView = (MapView) mBaseView.findViewById(R.id.bmapView);
		mBaiduMap = mMapView.getMap();
		// mCurrentMarker = BitmapDescriptorFactory .fromResource(R.drawable.icon_geo);
		 mBaiduMap  .setMyLocationConfigeration(new MyLocationConfiguration(  mCurrentMode, true, null));
        // 开启定位图层
        mBaiduMap.setMyLocationEnabled(true);
        // 定位初始化
        mLocClient = new LocationClient(getActivity().getApplicationContext());
        mLocClient.registerLocationListener(myListener);
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true); // 打开gps
        option.setCoorType("bd09ll"); // 设置坐标类型
        option.setScanSpan(2000);
        mLocClient.setLocOption(option);
        mLocClient.start();
		return mBaseView;
	}

	 
	
	
	 public class MyLocationListenner implements BDLocationListener {

	        @Override
	        public void onReceiveLocation(BDLocation location) {
	            // map view 销毁后不在处理新接收的位置
	            if (location == null || mMapView == null) {
	                return;
	            }
	            currentLatitude = location.getLatitude();
            	currentLongitude = location.getLongitude();
            	currentTime = new Date().getTime();
            	if(currentLatitude==4.9E-324||currentLatitude==4.9E-324){  
	            	return ;
	            }
            	
	            MyLocationData locData = new MyLocationData.Builder()
	                    .accuracy(location.getRadius())
	                            // 此处设置开发者获取到的方向信息,顺时针0-360
	                    .direction(100)
	                    .latitude(currentLatitude)
	                    .longitude(currentLongitude)
	                    .build();
	            mBaiduMap.setMyLocationData(locData);
	            
	            
 	            if(mLatitude == 0.0|| mLongitude ==0.0){
            		//return ;	
	            }else{
	            	 LatLng p1 = new LatLng(mLatitude, mLongitude);
	                 LatLng p2 = new LatLng(currentLatitude,currentLongitude ); 
	                 double distance = BaiduLBSUtil.getDistance(p1, p2);
	                 double  speed =distance / (currentTime - mTime == 0 ? 1:(currentTime - mTime )/1000);
	                 Log.e("baoyou", speed + "");
	                 
	                 if (    speed > 10) {
						return ;
					 } 
	                 List<LatLng> points = new ArrayList<LatLng>();
	                 points.add(p1);
	                 points.add(p2); 
	                 OverlayOptions ooPolyline11 = new PolylineOptions().width(10)
	                         .points(points).dottedLine(true).customTexture(mGreenTexture);
	                 mTexturePolyline = (Polyline) mBaiduMap.addOverlay(ooPolyline11);
	                
	            }    
	            
	            mLatitude  = currentLatitude;
	            mLongitude = currentLongitude;  
	            mTime = currentTime;
	            
	            Toast.makeText(getActivity().getApplication(), " currentLatitude =-"+currentLatitude +"currentLongitude =-"+currentLongitude , Toast.LENGTH_SHORT ).show();
				
	            Log.e("baoyou", "currentLatitude =-"+currentLatitude +"currentLongitude =-"+currentLongitude);
	            
	            if (isFirstLoc) {
	                isFirstLoc = false;
                LatLng ll = new LatLng(currentLatitude,currentLongitude);
                MapStatus.Builder builder = new MapStatus.Builder();
                builder.target(ll).zoom(18.0f);
                mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
	            }
	        }

	        public void onReceivePoi(BDLocation poiLocation) {
	        }
	    }

	  

	 @Override
	public void onPause() {
	        mMapView.onPause();
	        super.onPause();
	    }

	    @Override
		public void onResume() {
	        mMapView.onResume();
	        super.onResume();
	    }

	    @Override
		public void onDestroy() {
	        // 退出时销毁定位
	        mLocClient.stop();
	        // 关闭定位图层
	        mBaiduMap.setMyLocationEnabled(false);
	        mMapView.onDestroy();
	        mGreenTexture.recycle();
	        mMapView = null;
	        
	        super.onDestroy();
	    }

}

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.curiousby.demo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk  android:minSdkVersion="9" android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />  
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER"/>
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
     
    <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> 
    <uses-permission android:name="android.permission.GET_TASKS" />  
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.curiousby.demo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.curiousby.demo.running.RunningMainActivity"></activity>
        
        <service android:name="com.baidu.location.f"  android:enabled="true" android:process=":remote" >  </service>
        <meta-data   android:name="com.baidu.lbsapi.API_KEY"   android:value="gubKYsssq9ePIdVpBhz0VBfwx2PoMoYr" />
    
    
    </application>

</manifest>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

 

 

 

 

目录
相关文章
|
定位技术 API 开发工具
Android 按照步骤接入百度地图API,定位显示不了解决办法
Android 按照步骤接入百度地图API,定位显示不了解决办法
378 1
|
2月前
|
Java 测试技术 Android开发
Android性能测试——发现和定位内存泄露和卡顿
本文详细介绍了Android应用性能测试中的内存泄漏与卡顿问题及其解决方案。首先,文章描述了使用MAT工具定位内存泄漏的具体步骤,并通过实例展示了如何分析Histogram图表和Dominator Tree。接着,针对卡顿问题,文章探讨了其产生原因,并提供了多种测试方法,包括GPU呈现模式分析、FPS Meter软件测试、绘制圆点计数法及Android Studio自带的GPU监控功能。最后,文章给出了排查卡顿问题的四个方向,帮助开发者优化应用性能。
169 4
Android性能测试——发现和定位内存泄露和卡顿
|
6月前
|
API Android开发
Android高手进阶教程(十五)之---通过Location获取Address的使用!
Android高手进阶教程(十五)之---通过Location获取Address的使用!
63 1
|
3月前
|
开发工具 Android开发
Flutter: Android SDK not found at this location,Android Studio not found at xxx
Flutter: Android SDK not found at this location,Android Studio not found at xxx
157 2
|
6月前
|
JSON Java 定位技术
【Android App】GPS获取定位经纬度和根据经纬度获取详细地址讲解及实战(附源码和演示 超详细)
【Android App】GPS获取定位经纬度和根据经纬度获取详细地址讲解及实战(附源码和演示 超详细)
1874 0
|
6月前
|
安全 算法 JavaScript
安卓逆向 -- 关键代码定位与分析技术
安卓逆向 -- 关键代码定位与分析技术
155 0
|
6月前
|
XML Java 定位技术
【Android App】定位导航GPS中开启手机定位功能讲解及实战(附源码和演示 超详细)
【Android App】定位导航GPS中开启手机定位功能讲解及实战(附源码和演示 超详细)
298 0
|
Android开发 C语言
[笔记]安卓 使用breakpad定位崩溃问题
[笔记]安卓 使用breakpad定位崩溃问题
105 0
|
定位技术 Android开发 芯片
Android 中获取LocationProvider的三种方法和获取定位信息
Android 中获取LocationProvider的三种方法和获取定位信息
500 0
|
算法 测试技术 Android开发
Android逆向——定位到某书 Sign 算法(下)
Android逆向——定位到某书 Sign 算法(下)