Android Open Source - student_travel_app Location Module






From Project

Back to project page student_travel_app.

License

The source code is released under:

Apache License

If you think the Android project student_travel_app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.piasy.simpletravel.model;
// w ww. j a  v  a 2  s .c  o  m
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.LocationClientOption.LocationMode;
import com.piasy.simpletravel.controller.Controller;

public class LocationModule
{
  LocationClient locationClient;
  boolean aroudReqed = false;
  
  public LocationModule(LocationClient locationClient)
  {
    this.locationClient = locationClient;
    init();
    locationClient.requestLocation(); 
  }
  
  BDLocation mLocation = null;
  public BDLocation getLocation()
  {
    if (mLocation == null)
    {
      locationClient.requestLocation();
    }
    
    return mLocation;
  }
  
  public void reqLocation()
  {
    locationClient.requestLocation();
  }
  
  protected void init()
  {
    locationClient.registerLocationListener(new MyLocationListener());
    LocationClientOption option = new LocationClientOption();
    
//    //v 3.x
//    option.setOpenGps(true);
//    option.setAddrType("all");    //????????????????????
//    option.setCoorType("bd09ll");  //???????????????,???gcj02
//    option.setScanSpan(Constant.POS_REQ_TIMESTAMP);    //?????????????????300000 ms
//    option.disableCache(true);    //????????????
//    option.setPoiNumber(5);        //????POI??   
//    option.setPoiDistance(1000);  //poi?????        
//    option.setPoiExtraInfo(true);   //???????POI???????????????? 
    
    
    //v 4.x
    option.setOpenGps(true);
    option.setLocationMode(LocationMode.Hight_Accuracy);
    option.setIsNeedAddress(true);
    option.setCoorType("bd09ll");  //???????????????,???gcj02
    option.setScanSpan(Constant.POS_REQ_TIMESTAMP);    //?????????????????300000 ms  
    locationClient.setLocOption(option);
    locationClient.start();
    System.out.println("LocationModule.init(): loc client start!");
  }
  
  class MyLocationListener implements BDLocationListener
  {
    @Override
    public void onReceiveLocation(BDLocation location)
    {
      System.out
          .println("LocationModule.MyLocationListener.onReceiveLocation(): receive loc");
      if (location == null)
      {
        System.out
            .println("LocationModule.MyLocationListener.onReceiveLocation(): null loc");
        return;
      }
      
      int locType = location.getLocType();
      if (!(locType == BDLocation.TypeGpsLocation || locType == BDLocation.TypeNetWorkLocation))
      {
        System.out
            .println("LocationModule.MyLocationListener.onReceiveLocation(): bad loc type");
        return;
      }
      mLocation = location;
      if (!aroudReqed)
      {
        Controller.getController().searchAroundSpots();
        System.out
            .println("LocationModule.MyLocationListener.onReceiveLocation(): search around");
        aroudReqed = true;
      }
      System.out
          .println("LocationModule.MyLocationListener.onReceiveLocation(): update loc");
    }
    
  }
}




Java Source Code List

com.piasy.simpletravel.AllPlanActivity.java
com.piasy.simpletravel.HotelDetailActivity.java
com.piasy.simpletravel.LaunchActivity.java
com.piasy.simpletravel.MapViewActivity.java
com.piasy.simpletravel.MyListViewAdapter.java
com.piasy.simpletravel.PopMenu.java
com.piasy.simpletravel.ScrollRefreshListView.java
com.piasy.simpletravel.SearchActivity.java
com.piasy.simpletravel.SettingActivity.java
com.piasy.simpletravel.SignupActivity.java
com.piasy.simpletravel.SimpleTravelApplication.java
com.piasy.simpletravel.SingledayPlanActivity.java
com.piasy.simpletravel.SpotDetailActivity.java
com.piasy.simpletravel.controller.Controller.java
com.piasy.simpletravel.dao.DBHelper.java
com.piasy.simpletravel.dao.DBManager.java
com.piasy.simpletravel.model.CommitModule.java
com.piasy.simpletravel.model.Constant.java
com.piasy.simpletravel.model.Flag.java
com.piasy.simpletravel.model.HotelSeacher.java
com.piasy.simpletravel.model.ListViewItems.java
com.piasy.simpletravel.model.LocationModule.java
com.piasy.simpletravel.model.PlanGenerator.java
com.piasy.simpletravel.model.RouteEntry.java
com.piasy.simpletravel.model.Setting.java
com.piasy.simpletravel.model.SignupModule.java
com.piasy.simpletravel.model.SpotsSeacher.java
com.piasy.simpletravel.model.VerifyModule.java
com.piasy.simpletravel.util.Util.java
dao.DBManager.java
driver.Driver.java
model.CommitHandler.java
model.Constant.java
model.QueryHandler.java
model.Setting.java
model.SignupHandler.java
model.VerifyHandler.java
parser.Driver.java
parser.HotelSeacher.java
util.Util.java