android开源项目旅游记录

项目名字:AndTripLog-旅游日记

一个很好的学习定位的开源项目,用的是google的定位系统,

但是google的基站定位在国内很不稳定,基本处于不能用的状态

本着自己动手丰衣足食的精神,果断改成百度的定位系统,

写了一个百度定位的工具类:

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;

import com.baidu.location.*;
public class LocationUtils {
    private Context context;
    private boolean isLocationupdate=false;
    private String locationInfo;
    private Handler mhandler;
    private BDLocation bdLocation;
    public LocationClient mLocationClient = null;
    public MyLocationListenner myListener = new MyLocationListenner();
    
	public LocationUtils(Context context,Handler myhandler){
		this.context=context;
		mhandler=myhandler;
	}
	
	class MyLocationListenner implements BDLocationListener{

		public void onReceiveLocation(BDLocation location) {
			// TODO Auto-generated method stub
			Log.d("AndTripLog","onReceiveLocation");
			if (location == null)
				return ;
			Log.d("AndTripLog","onReceiveLocation is not null");
			bdLocation=location;
			isLocationupdate=true;
			locationInfo="Latitude:"+location.getLatitude()+",Longitude:"+location.getLongitude();
			mhandler.sendEmptyMessage(0);
		}

		public void onReceivePoi(BDLocation poiLocation) {
			// TODO Auto-generated method stub
			if (poiLocation == null){
				return ; 
			}
		}
		
	}
	public String getLocationInfo(){
		return locationInfo;		
	}
	public BDLocation getLocation(){
		return bdLocation;
	}
	public void startLocation(){
		isLocationupdate=false;
		mLocationClient = new LocationClient(context);	
		setLocationOption();
		mLocationClient.registerLocationListener(myListener);
		Log.d("lostprevent","startLocation");
		mLocationClient.start();
	}
	public boolean isupdate(){
		return isLocationupdate;
	}
	public void stopLocation(){
		isLocationupdate=false;
		mLocationClient.stop();
	}
	private void setLocationOption(){
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(true);				
		option.setServiceName("com.baidu.location.service_v3.3");
		option.setPoiExtraInfo(false);	
        option.setAddrType("all");	
		option.setScanSpan(3000);
        option.setCoorType("bd09ll"); 
        option.setPriority(LocationClientOption.NetWorkFirst);   
		option.disableCache(true);		
		mLocationClient.setLocOption(option);
	}

}


相应的权限设置、需要添加的包见官方的介绍:

http://developer.baidu.com/map/geosdk-android-developv3.3.htm

通过此项目学习,可以很好的学习知识点:

1.定位系统

2.SQLite语句

3.文件保存

4.邮件发送

项目源码下载地址:

http://download.csdn.net/detail/txj8612/5353448




原文地址:https://www.cnblogs.com/xinyuyuanm/p/3071792.html