百度地图定位基础 (四)

2014-11-24 11:17:34 · 作者: · 浏览: 6
e(R.menu.local, menu);
return true;
}

@Override
protected void onStop() {
super.onStop();
if (mLocationClient != null) {
mLocationClient.stop();
mLocationClient = null;
}
}

public class MyLocationListener implements BDLocationListener{

//接收异步返回的定位结果,参数是BDLocation类型参数
@Override
public void onReceiveLocation(BDLocation location) {
if (location == null) {
return;
}
StringBuffer sb = new StringBuffer(256);
sb.append("time: ");
sb.append(location.getTime());
sb.append("\nerror code: ");
sb.append(location.getLocType());
sb.append("\nlontitude: ");
sb.append(location.getLongitude());
sb.append("\nradius: ");
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation) {
sb.append("\nspedd: ");
sb.append(location.getSpeed());
sb.append("\nsatellite: ");
sb.append(location.getSatelliteNumber());
}else if(location.getLocType() == BDLocation.TypeNetWorkLocation){
sb.append("\naddr: ");
sb.append(location.getAddrStr());
}else if(location.getLocType() == BDLocation.TypeOffLineLocation || location.getLocType() == BDLocation.TypeOffLineLocationNetworkFail){

}
if (contentTextView != null) {
contentTextView.setText(sb.toString());
}
}

//接收异步返回的POI查询结果,参数是BDLocation类型参数
@Override
public void onReceivePoi(BDLocation arg0) {

}
}

//BDNotifyListener实现
public class NotifyLister extends BDNotifyListener{
public void onNotify(BDLocationListener mListener, float distance){
if (mVibrator == null) {
mVibrator = (Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);
}
mVibrator.vibrate(1000);//振动提醒已到设定位置附近
}
}
public LocationClient mLocationClient = null;
LocationClientOption option;
public BDLocationListener myListener;
public NotifyLister mNotifyer;
public Vibrator mVibrator;

private TextView contentTextView;
private Button localButton;
private Button poiButton;
private Button notifyButton;
private Button offlineButton;
private RelativeLayout Parent;
private LinearLayout bottomLayout;

public int Screen_width;
public int Screen_height;
public float scale;
public int buttonWidth = 130;//dp
public int buttonHeight = 50;//dp

public boolean clickNotify = false;

}

package com.zhangjie.local;

import android.os.Bundle;
import android.os.Vibrator;
import android.app.Activity;
import android.app.Service;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import andr