Android使用腾讯定位SDK显示当前地址

来源:互联网 发布:淘宝上好评后怎么截图 编辑:程序博客网 时间:2024/06/05 10:51

照着书上例子准备做个定位小程序,使用例子中的聚合数据接口发现有次数限制,然后准备换到百度地图SDK,准备先做出定位再完善成LBS,没想到百度注册为开发者太麻烦,还要手持身份证拍照,于是换到腾讯地图。
腾讯定位SDK简介安装:http://lbs.qq.com/geo/guide-install.html

文本显示当前地址的简单demo如下:

public class MainActivity extends Activity implements TencentLocationListener{    private TextView mStatus;    private TencentLocation mLocation;    private TencentLocationManager mLocationManager;    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        mStatus = (TextView) findViewById(R.id.mStatus);mLocationManager = TencentLocationManager.getInstance(this);        mLocationManager.requestLocationUpdates(TencentLocationRequest.create().setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_NAME).setInterval(500).setAllowDirection(true), this);    }    public void onLocationChanged(TencentLocation location, int error,String reason) {    if (error == TencentLocation.ERROR_OK) {            // 定位成功        mLocation = location;        StringBuilder sb = new StringBuilder();        sb.append("(纬度=").append(location.getLatitude()).append(",经度=").append(location.getLongitude()).append(",精度=").append(location.getAccuracy()).append("), 来源=").append(location.getProvider()).append(", 地址=").append(location.getAddress());            // 更新 status    mStatus.setText(sb.toString());        }    }    public void onStatusUpdate(String arg0, int arg1, String arg2) {        // TODO Auto-generated method stub    }    protected void onDestroy() {        // TODO Auto-generated method stub        super.onDestroy();        mLocationManager.removeUpdates(this);    }}
0 0
原创粉丝点击