Project name: andtriplog-Travel Diary
A good open-source project for learning and positioning, using Google's positioning system,
However, Google's base stations are very unstable in China and are basically unavailable.
In the spirit of self-help clothing and food, the positioning system of Baidu was changed to a decisive one,
I wrote a tool class for Baidu positioning:
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 stubLog.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 stubif (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);}}
For the corresponding permission settings and packages to be added, see the official introduction:
Http://developer.baidu.com/map/geosdk-android-developv3.3.htm
Through this project, you can learn knowledge points well:
1. Positioning System
2. SQLite statement
3. Save the file
4. Email sending
Project source code:
Http://download.csdn.net/detail/txj8612/5353448
Android default positioning system class locationmanager:
myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); myLocationManager.requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener)
Provider: Specifies the positioning type: gps_provider is GPS positioning, network_provider is base station positioning
Mintime: Minimum positioning Interval
Mindistance: Minimum positioning Interval
Listener: locates the listener and implements four Abstract methods of the interface locationlistener:
abstract voidonLocationChanged(Location location) //Called when the location has changed.abstract voidonProviderDisabled(String provider) //Called when the provider is disabled by the user.abstract voidonProviderEnabled(String provider) //Called when the provider is enabled by the user.abstract voidonStatusChanged(String provider, int status, Bundle extras) //Called when the provider status changes.
The location information is obtained from the location in onlocationchanged (location.