import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.BDNotifyListener;//假如用到位置提醒功能,需要import该类
public class Local extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getDisplayMetrics();
initLayout();
setContentView(Parent);
myListener = new MyLocationListener();
mLocationClient = new LocationClient(getApplicationContext());
mLocationClient.registerLocationListener(myListener);
//设置定位参数包括:定位模式(单次定位,定时定位),返回坐标类型,是否打开GPS等等
option = new LocationClientOption();
option.setOpenGps(true);
option.setAddrType("all");//返回定位结果包含地址信息
option.setCoorType("bd0911");//返回的定位结果是百度经纬度,默认值gcj02
option.setScanSpan(5000);//设置发起请求的时间间隔为5000ms
option.disableCache(true);//禁止开启缓存定位
option.setPoiNumber(5);//最多返回POI个数
option.setPoiDistance(1000);//poi查询距离
option.setPoiExtraInfo(true);//是否需要POI的电话和地址等详细信息
mLocationClient.setLocOption(option);
mLocationClient.start();
}
/**
* 初始化布局
*/
public void initLayout(){
Parent = new RelativeLayout(this);
bottomLayout = new LinearLayout(this);
bottomLayout.setId(10);
contentTextView = new TextView(this);
contentTextView.setText(R.string.content);
localButton.setText(R.string.localrequest);
localButton.setId(11);
localButton.setOnClickListener(this);
poiButton = new Button(this);
poiButton.setText(R.string.poirequest);
poiButton.setId(12);
poiButton.setOnClickListener(this);
notifyButton = new Button(this);
notifyButton.setText(R.string.notify);
notifyButton.setId(13);
notifyButton.setOnClickListener(this);
offlineButton = new Button(this);
offlineButton.setText(R.string.offine);
offlineButton.setId(14);
offlineButton.setOnClickListener(this);
// 置底部 局的button
int disten = (Screen_width - dip2px(buttonWidth) * 4) / 5;
LinearLayout.LayoutParams buttonInBottomLayoutParams = new LinearLayout.LayoutParams(dip2px(buttonWidth), dip2px(buttonHeight));
buttonInBottomLayoutParams.leftMargin = disten;
bottomLayout.addView(localButton, buttonInBottomLayoutParams);
bottomLayout.addView(poiButton, buttonInBottomLayoutParams);
bottomLayout.addView(notifyButton, buttonInBottomLayoutParams);
bottomLayout.addView(offlineButton, buttonInBottomLayoutParams);
RelativeLayout.LayoutParams bottomInParentLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
bottomInParentLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
Parent.addView(bottomLayout, bottomInParentLayoutParams);
// 置contentTextView 局
RelativeLayout.LayoutParams contentInParentLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
contentInParentLayoutParams.addRule(RelativeLayout.ABOVE, 10);
Parent.addView(contentTextView, contentInParentLayoutParams);
}
@Override
public void o