Java Code Examples for com.tencent.map.geolocation.TencentLocation

The following examples show how to use com.tencent.map.geolocation.TencentLocation. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DoraemonKit   Source File: TencentLocationListenerProxy.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {
    if (GpsMockManager.getInstance().isMocking()) {
        try {
            //tencentLocation 的 对象类型为TxLocation
            //LogHelper.i(TAG, "matched==onLocationChanged==" + tencentLocation.toString());
            //b 为fb类型
            Object b = ReflectUtils.reflect(tencentLocation).field("b").get();
            //a 为lat
            ReflectUtils.reflect(b).field("a", GpsMockManager.getInstance().getLatitude());
            //b 为lng
            ReflectUtils.reflect(b).field("b", GpsMockManager.getInstance().getLongitude());
            //LogHelper.i(TAG, "b===>" + b.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    if (tencentLocationListener != null) {
        tencentLocationListener.onLocationChanged(tencentLocation, i, s);
    }
}
 
Example 2
Source Project: LQRWeChat   Source File: MyLocationActivity.java    License: MIT License 6 votes vote down vote up
@Override
public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {
    if (i == tencentLocation.ERROR_OK) {
        LatLng latLng = new LatLng(tencentLocation.getLatitude(), tencentLocation.getLongitude());
        if (myLocation == null) {
            myLocation = mTencentMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.mipmap.arm)).anchor(0.5f, 0.8f));
        }
        if (accuracy == null) {
            accuracy = mTencentMap.addCircle(new CircleOptions().center(latLng).radius(tencentLocation.getAccuracy()).fillColor(0x440000ff).strokeWidth(0f));
        }
        myLocation.setPosition(latLng);
        accuracy.setCenter(latLng);
        accuracy.setRadius(tencentLocation.getAccuracy());
        mTencentMap.animateTo(latLng);
        mTencentMap.setZoom(16);
        search(latLng);
        //取消定位
        mLocationManager.removeUpdates(MyLocationActivity.this);
    } else {
        LogUtils.sf("location failed:" + i);
    }
}
 
Example 3
@Override
public void onLocationChanged(TencentLocation location, int error, String reason) {
    if (latitude == 0 && longtitude == 0) {
        latitude = location.getLatitude();
        longtitude = location.getLongitude();
        Toast toast = Toast.makeText(getApplicationContext(), "定位成功", Toast.LENGTH_SHORT);
        toast.show();
    }
    // 自动点击屏幕操作
    // int x = metrics.widthPixels / 2;
    // int y = metrics.heightPixels / 2 - 50 * 3 / 2;
    // String[] order = {"input", "tap", "" + x, "" + y};
    // try {
    //     new ProcessBuilder(order).start();
    // } catch (IOException e) {
    //     e.printStackTrace();
    // }


    if (firstLocation && latitude != 0 && longtitude != 0) {
        firstLocation = false;
        tencentMap.setCenter(new LatLng(latitude, longtitude));
    }
    if (!isMarker) {
        marker = tencentMap.addMarker(new MarkerOptions()
                .icon(BitmapDescriptorFactory.defaultMarker())
                .draggable(true));
        isMarker = true;
    }
    marker.setPosition(new LatLng(latitude, longtitude));
}