辅助功能

辅助功能会提供开发者比较常用的实现,辅助功能通过TencentLocationUtils工具类对外暴露。


1、计算两点之间距离

//两个点之间的距离
double distanceBetween(TencentLocation aLoc, TencentLocation bLoc)
//两个点以经纬度的形式计算距离 
double distanceBetween(double aLatitude, double aLongitude, double bLatitude, double bLongitude)

2、判断一个点是否在一片圆形区域内

boolean contains(TencentLocation center, double radius, TencentLocation aPoint)

3、是否是GPS定位

boolean isFromGps(TencentLocation location)

4、是否是网络定位

boolean isFromNetwork(TencentLocation location)

5、判断设备是否支持GPS定位

boolean isSupportGps(Context context)

6、拓展

以上方法怎么把获取的经纬度按转化为TencentLocation 呢?

//实现TencentLocation 设置对应经纬度
public class MyLocation implements TencentLocation {
    private double mLatitude;
    private double mLongitude;

    public MyLocation(double latitude, double longitude) {
        mLatitude = latitude;
        mLongitude = longitude;
    }

    @Override
    public double getLatitude() {
        return mLatitude;
    }

    @Override
    public double getLongitude() {
        return mLongitude;
    }
}

本页内容