Beispiel #1
0
  /**
   * 定位当前位置
   *
   * @return
   */
  public BDLocation getLocation() {
    mLocationClient = new LocationClient(mContext.getApplicationContext());
    // mLocationClient.registerLocationListener(myListener);
    // mLocationClient.setAK("eWeT5sSsDuzlGzfaVGyShoeG");
    // LocationClientOption option = new LocationClientOption();
    // option.setOpenGps(false);
    // option.setAddrType("all");
    // option.setServiceName("com.baidu.location.service_v2.9");

    mLocationClient.registerLocationListener(myListener);
    // mLocationClient.setAK("eWeT5sSsDuzlGzfaVGyShoeG");
    LocationClientOption option = new LocationClientOption();
    option.setOpenGps(false);
    option.setAddrType("all");
    option.setServiceName("com.baidu.location.service_v2.9");
    // 返回国测局经纬度坐标系 coor=gcj02
    // 返回百度墨卡托坐标系 coor=bd09
    // 返回百度经纬度坐标系 coor=bd09ll
    option.setCoorType("gcj02");
    option.setScanSpan(900);
    option.disableCache(true);
    option.setPriority(LocationClientOption.NetWorkFirst);
    mLocationClient.setLocOption(option);
    if (mLocationClient != null) {
      mLocationClient.start();
      mLocationClient.requestLocation();
    } else {

    }
    return null;
  }
  private void initLocClient() {
    // 开启定位图层
    mBaiduMap.setMyLocationEnabled(true);
    mBaiduMap.setMyLocationConfigeration(
        new MyLocationConfigeration(
            com.baidu.mapapi.map.MyLocationConfigeration.LocationMode.NORMAL, true, null));
    // 定位初始化
    mLocClient = new LocationClient(this);
    mLocClient.registerLocationListener(myListener);
    LocationClientOption option = new LocationClientOption();
    option.setProdName("bmobim"); // 设置产品线
    option.setOpenGps(true); // 打开gps
    option.setCoorType("bd09ll"); // 设置坐标类型
    option.setScanSpan(1000);
    option.setOpenGps(true);
    option.setIsNeedAddress(true);
    option.setIgnoreKillProcess(true);
    mLocClient.setLocOption(option);
    mLocClient.start();
    if (mLocClient != null && mLocClient.isStarted()) mLocClient.requestLocation();

    if (lastLocation != null) {
      // 显示在地图上
      LatLng ll = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
      MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
      mBaiduMap.animateMapStatus(u);
    }
  }
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(BaiduMapAll.LOG_TAG, "启动LocationApplication!");
    MyLog.i(BaiduMapAll.LOG_TAG, "启动LocationApplication!");

    // this.setUploadUrl(intent.getStringExtra("uploadUrl"));
    // this.setGps_interval(intent.getIntExtra("gps_interval",0));
    //		String params_str=intent.getStringExtra("params");
    //		try {
    //			if(params_str!=null){
    //				this.setParams(new JSONObject(params_str));
    //
    //			}
    //
    //		} catch (JSONException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //			Log.e(BaiduMapAll.LOG_TAG, e.getMessage());
    //		}
    // mLocationClient.getLocOption().setScanSpan(this.getGps_interval());
    initLocation();

    mLocationClient.start();
    mLocationClient.requestLocation();

    // toast("开始获取gps信息了", Toast.LENGTH_LONG);
    // LOG.i(BaiduMapAll.LOG_TAG, "开始获取gps信息了================================================");
    return super.onStartCommand(intent, flags, startId);
  }
Beispiel #4
0
 /** 开始定位 */
 public void startLocation() {
   if (mLocationClient != null && !mLocationClient.isStarted()) {
     mLocationClient.registerLocationListener(mLocationListener);
     mLocationClient.start();
     mLocationClient.requestLocation();
   }
 }
  @Override
  protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "handle new location request.");

    int seq = intent.getIntExtra("seq", -1);
    String type = intent.getStringExtra("type");
    String id = intent.getStringExtra("id");
    if (TextUtils.isEmpty(type) || TextUtils.isEmpty(id)) {
      Log.d(TAG, "LocationIntentService got invaild intent.");
      return;
    }

    synchronized (mSyncObject) {
      if (mLocationClient != null) {
        int retCode = mLocationClient.requestLocation();
        Log.d(TAG, "retCode:" + retCode);
        try {
          mSyncObject.wait();
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
    if (MainActivity.VISIBLE
        || !PrefUtil.getbooleanValue(getApplicationContext(), "pref_loc_me_silent_enable", false)) {
      MessageHelper.sendServerMsgToList(
          seq, "client", getString(R.string.loc_sending_loc), getApplicationContext());
    }
    sendResultToServer(formatResponse(id));
    Log.d(TAG, "LocationIntentService exit intent.");
  }
Beispiel #6
0
  private View getHeadView() {
    View view = LayoutInflater.from(this).inflate(R.layout.city_headview, null);
    mGridView = (MyGridView) view.findViewById(R.id.gv_headview_city);
    final String[] datas = this.getResources().getStringArray(R.array.hot_city);
    mGridView.setAdapter(new CityHeadViewAdapter(this));

    mLocationClient = new LocationClient(getApplicationContext()); //
    mLocationClient.registerLocationListener(myListener); //
    cityButton = (Button) view.findViewById(R.id.cityButton);
    LocationClientOption option = new LocationClientOption();
    option.setOpenGps(true); // 打开GPS
    option.setAddrType("all"); //
    option.setCoorType("bd09ll"); //
    option.setScanSpan(3000); //
    option.disableCache(false); //
    option.setPriority(LocationClientOption.NetWorkFirst); //
    mLocationClient.setLocOption(option); //
    mLocationClient.start(); //
    mLocationClient.requestLocation(); //
    mGridView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub

            cityButton.setText(datas[position]);
            stopListener();
            Intent intent = new Intent();
            String city = cityButton.getText().toString();
            intent.putExtra("city", city);
            CityList.this.setResult(RESULT_OK, intent);
            CityList.this.finish();
          }
          //
          //			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
          //					long arg3) {
          //				if (isnext == 7) {
          //					String city = cities.get(arg2 - 1).getName();
          //					AppContext appContext = (AppContext) getApplicationContext();
          //					appContext.setCity(city);
          //					startActivity(new Intent(SelectCityActivity.this,
          //							MainActivity.class));
          //					finish();
          //				} else {
          //					String city = cities.get(arg2 - 1).getName();
          //					Intent intent = new Intent(SelectCityActivity.this,
          //							MainActivity.class);
          //					intent.putExtra("city", city);
          //					setResult(1, intent);
          //					finish();
          //				}
          //			}
        });
    return view;
  }
Beispiel #7
0
 public static void getLocation(Context context, LocationSuccessListener locationSuc) {
   locationSuccess = locationSuc;
   if (mLocationClient == null) {
     mLocationClient = new LocationClient(context);
     mLocationClient.setLocOption(getLocOption());
     mLocationClient.registerLocationListener(new MyLocationListener());
   }
   mLocationClient.start();
   mLocationClient.requestLocation();
   return;
 }
  private void initBaiduMap() {
    mapView = (MapView) findViewById(R.id.bmapView);
    baiduMap = mapView.getMap();
    baiduMap.setMaxAndMinZoomLevel(18, 13);
    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
    iFilter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
    receiver = new BaiduReceiver();
    registerReceiver(receiver, iFilter);

    geoCoder = GeoCoder.newInstance();
    geoCoder.setOnGetGeoCodeResultListener(this);

    Intent intent = getIntent();
    intentType = intent.getStringExtra(TYPE);
    initActionBar(R.string.chat_position);
    if (intentType.equals(TYPE_SELECT)) {
      // 选择发送位置
      // 开启定位图层
      baiduMap.setMyLocationEnabled(true);
      baiduMap.setMyLocationConfigeration(
          new MyLocationConfigeration(MyLocationConfigeration.LocationMode.NORMAL, true, null));
      // 定位初始化
      locClient = new LocationClient(this);
      locClient.registerLocationListener(myListener);
      LocationClientOption option = new LocationClientOption();
      option.setProdName("avosim");
      option.setOpenGps(true);
      option.setCoorType("bd09ll");
      option.setScanSpan(1000);
      option.setOpenGps(true);
      option.setIsNeedAddress(true);
      option.setIgnoreKillProcess(true);
      locClient.setLocOption(option);
      locClient.start();
      if (locClient != null && locClient.isStarted()) {
        locClient.requestLocation();
      }
      if (lastLocation != null) {
        // 显示在地图上
        LatLng ll = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
        MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
        baiduMap.animateMapStatus(u);
      }
    } else {
      Bundle b = intent.getExtras();
      LatLng latlng = new LatLng(b.getDouble(LATITUDE), b.getDouble(LONGITUDE)); // 维度在前,经度在后
      baiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(latlng));
      OverlayOptions ooA = new MarkerOptions().position(latlng).icon(descriptor).zIndex(9);
      baiduMap.addOverlay(ooA);
    }
  }
Beispiel #9
0
  /** 开始定位服务, activity的onResume中设置监听,用于回调 */
  public void startLocatingActive(OnLocationUpdateListener loclistener, int wait) {
    ci = CommonInfo.getInstance();

    option.setOpenGps(true); // 打开gps
    option.setCoorType("bd09ll"); // 设置坐标类型
    option.setScanSpan(wait);

    mLocClient.registerLocationListener(myListener);
    mLocClient.setLocOption(option);
    mLocClient.start();
    mLocClient.requestLocation();
    LocListener = loclistener;
  }
 /** 手动触发一次定位请求 */
 public void requestLocClick() {
   Log.d("qianjin", "qianjinrequestLocClick");
   isRequest = true;
   mLocClient.requestLocation();
   Toast.makeText(LocationOverlayDemo.this, "正在定位……", Toast.LENGTH_SHORT).show();
 }
 public void detect() {
   if (!locationClient.isStarted()) locationClient.start();
   locationClient.requestLocation();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    try {
      super.onCreate(savedInstanceState);
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.activity_hotel_location);
      ((MyApplication) getApplication()).addActivity(this);

      mMapView = (MapView) findViewById(R.id.bmapView);
      mBaidumap = mMapView.getMap();

      ((ImageButton) findViewById(R.id.back_imgbtn))
          .setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View v) {
                  finish();
                }
              });

      mLocationClient = new LocationClient(this.getApplicationContext());
      mLocationClient.registerLocationListener(new MyLocationListener());
      InitLocation();
      mLocationClient.start();
      mLocationClient.requestLocation();

      HotelDetail maphotel = null;
      Marker marker = null;
      BitmapDescriptor mIconMaker;
      OverlayOptions overlayOptions = null;
      Bundle bundle = this.getIntent().getExtras();
      if (bundle != null)
        if (bundle.containsKey("hotel"))
          try {
            maphotel = JSONHelper.parseObject(bundle.getString("hotel"), HotelDetail.class);
          } catch (Exception e) {
            e.printStackTrace();
          }
      LatLng latLng =
          new LatLng(Double.parseDouble(maphotel.getY()), Double.parseDouble(maphotel.getX()));
      hotelY = Double.parseDouble(maphotel.getY());
      hotelX = Double.parseDouble(maphotel.getX());
      View view = getMapView(maphotel.getHotelname(), maphotel.getMin_price());
      mIconMaker = BitmapDescriptorFactory.fromView(view);
      // 图标
      overlayOptions = new MarkerOptions().position(latLng).icon(mIconMaker).zIndex(5);
      marker = (Marker) (mBaidumap.addOverlay(overlayOptions));

      // 设定中心点坐标
      MapStatus mMapStatus = new MapStatus.Builder().target(latLng).zoom(16).build();
      // 定义MapStatusUpdate对象,以便描述地图状态将要发生的变化
      MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
      mBaidumap.setMapStatus(mMapStatusUpdate);

      mBaidumap.setOnMarkerClickListener(
          new OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(final Marker marker) {
              // startNavi();
              return true;
            }
          });

      ((ImageButton) findViewById(R.id.navi_imgbtn))
          .setOnClickListener(
              new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                  startNavi();
                }
              });
    } catch (Exception e) {
      e.printStackTrace();
    }
  }