<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/height_top_bar"
android:background="@color/common_top_bar_dark"
android:gravity="center_vertical">
<Button
android:id="@+id/btn_location_back"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:drawableLeft="@drawable/back"
android:text="@string/top_back"
style="@style/btn_title_bar"
android:layout_alignParentLeft="true"
android:onClick="back"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/location_message"
style="@style/txt_titlebar_message"/>
<Button
android:id="@+id/btn_location_ok"
android:layout_width="52dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="@drawable/common_tab_bg"
android:text="@string/txt_queding"
style="@style/btn_title_bar"/>
</RelativeLayout>
<com.baidu.mapapi.map.MapView
android:layout_weight="2"
android:id="@+id/mapview_location"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:clickable="true" />
<ListView
android:layout_weight="3"
android:id="@+id/lv_location_nearby"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
/**
* 初始化组件
*/
private void initView() {
btnLocationBack = (Button) findViewById(R.id.btn_location_back);
btnLocationBack.setOnClickListener(this);
btnLocationOk = (Button) findViewById(R.id.btn_location_ok);
btnLocationOk.setOnClickListener(this);
mapViewLocation = (MapView) findViewById(R.id.mapview_location);
lvLocNear = (ListView) findViewById(R.id.lv_location_nearby);
nearList = new ArrayList<PoiInfo>();
adapter = new LocNearAddressAdapter(context, nearList, isSelected);
lvLocNear.setAdapter(adapter);
}
public LocationClient mLocationClient = null;
public BDLocationListener myListener = new MyLocationListener();
public void onCreate() {
mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类
mLocationClient.registerLocationListener( myListener ); //注册监听函数
}
private void initLocation(){
LocationClientOption option = new LocationClientOption();
option.setLocationMode(LocationMode.Hight_Accuracy
);//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系
int span=1000;
option.setScanSpan(span);//可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
option.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要
option.setOpenGps(true);//可选,默认false,设置是否使用gps
option.setLocationNotify(true);//可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
option.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
option.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
option.setIgnoreKillProcess(false);//可选,默认false,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认杀死
option.SetIgnoreCacheException(false);//可选,默认false,设置是否收集CRASH信息,默认收集
option.setEnableSimulateGps(false);//可选,默认false,设置是否需要过滤gps仿真结果,默认需要
mLocationClient.setLocOption(option);
}
/**
* 监听函数,有新位置的时候,格式化成字符串,输出到屏幕中
*/
public class MyLocationListenner implements BDLocationListener {
@Override
public void onReceiveLocation(BDLocation location) {
if (location == null) {
return;
}
Log.d("map", "On location change received:" + location);
Log.d("map", "addr:" + location.getAddrStr());
if (progressDialog != null) {
progressDialog.dismiss();
}
if (lastLocation != null) {
if (lastLocation.getLatitude() == location.getLatitude() && lastLocation.getLongitude() == location.getLongitude()) {
Log.d("map", "same location, skip refresh");
// mMapView.refresh(); //need this refresh?
return;
}
}
lastLocation = location;
mBaiduMap.clear();
mCurrentLantitude = lastLocation.getLatitude();
mCurrentLongitude = lastLocation.getLongitude();
Log.e(">>>>>>>", mCurrentLantitude + "," + mCurrentLongitude);
LatLng llA = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude());
CoordinateConverter converter = new CoordinateConverter();
converter.coord(llA);
converter.from(CoordinateConverter.CoordType.COMMON);
LatLng convertLatLng = converter.convert();
OverlayOptions ooA = new MarkerOptions().position(convertLatLng).icon(BitmapDescriptorFactory
.fromResource(R.drawable.icon_marka))
.zIndex(4).draggable(true);
mCurrentMarker = (Marker) mBaiduMap.addOverlay(ooA);
MapStatusUpdate u = MapStatusUpdateFactory.newLatLngZoom(convertLatLng, 16.0f);
mBaiduMap.animateMapStatus(u);
new Thread(new Runnable() {
@Override
public void run() {
searchNeayBy();
}
}).start();
}
public void onReceivePoi(BDLocation poiLocation) {
if (poiLocation == null) {
return;
}
}
}
/*
* 显示经纬度的位置
* */
private void showMap(double latitude, double longtitude, String address) {
// sendButton.setVisibility(View.GONE);
LatLng llA = new LatLng(latitude, longtitude);
CoordinateConverter converter = new CoordinateConverter();
converter.coord(llA);
converter.from(CoordinateConverter.CoordType.COMMON);
LatLng convertLatLng = converter.convert();
OverlayOptions ooA = new MarkerOptions().position(convertLatLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marka))
.zIndex(4).draggable(true);
markerA = (Marker) (mBaiduMap.addOverlay(ooA));
u = MapStatusUpdateFactory.newLatLngZoom(convertLatLng, 16.0f);
mBaiduMap.animateMapStatus(u);
new Thread(new Runnable() {
@Override
public void run() {
searchNeayBy();
}
}).start();
}
/**
* 搜索周边地理位置
*/
private void searchNeayBy() {
PoiNearbySearchOption option = new PoiNearbySearchOption();
option.keyword("写字楼");
option.sortType(PoiSortType.distance_from_near_to_far);
option.location(new LatLng(mCurrentLantitude, mCurrentLongitude));
if (radius != 0) {
option.radius(radius);
} else {
option.radius(1000);
}
option.pageCapacity(20);
mPoiSearch.searchNearby(option);
}
/*
* 接受周边地理位置结果
* @param poiResult
*/
@Override
public void onGetPoiResult(PoiResult poiResult) {
if (poiResult != null) {
if (poiResult.getAllPoi()!=null&&poiResult.getAllPoi().size()>0){
nearList.addAll(poiResult.getAllPoi());
if (nearList != null && nearList.size() > 0) {
for (int i = 0; i < nearList.size(); i++) {
isSelected.put(i, false);
}
}
Message msg = new Message();
msg.what = 0;
handler.sendMessage(msg);
}
}
}
/**
* 周边地理位置列表点击事件
*/
lvLocNear.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
adapter.setSelected(i);
adapter.notifyDataSetChanged();
PoiInfo ad = (PoiInfo) adapter.getItem(i);
u = MapStatusUpdateFactory.newLatLng(ad.location);
mBaiduMap.animateMapStatus(u);
if (!isLoc) {
mCurrentMarker.setPosition(ad.location);
} else {
markerA.setPosition(ad.location);
}
}
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有