use of com.amap.api.services.geocoder.RegeocodeResult in project KL2 by jweihao.
the class GaoDeActivity method initListener.
private void initListener() {
// 监测地图画面的移动
mAMap.setOnCameraChangeListener(new AMap.OnCameraChangeListener() {
@Override
public void onCameraChangeFinish(CameraPosition cameraPosition) {
if (null != location && null != cameraPosition && isSearchData) {
mIvLocation.setImageResource(R.mipmap.location_gps_black);
zoom = cameraPosition.zoom;
if (null != mSelectByListMarker) {
mSelectByListMarker.setVisible(false);
}
getAddressInfoByLatLong(cameraPosition.target.latitude, cameraPosition.target.longitude);
startTransAnimator();
// doSearchQuery(true, "", location.getCity(), new LatLonPoint(cameraPosition.target.latitude, cameraPosition.target.longitude));
}
if (!isSearchData) {
isSearchData = true;
}
}
@Override
public void onCameraChange(CameraPosition cameraPosition) {
}
});
// 设置触摸地图监听器
mAMap.setOnMapClickListener(new AMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
isSearchData = true;
}
});
// Poi搜索监听器
mOnPoiSearchListener = new onPoiSearchLintener();
// 逆地址搜索监听器
mOnGeocodeSearchListener = new GeocodeSearch.OnGeocodeSearchListener() {
@Override
public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
if (i == 1000) {
if (regeocodeResult != null) {
userSelectPoiItem = DataConversionUtils.changeToPoiItem(regeocodeResult);
if (null != mList) {
mList.clear();
}
mList.addAll(regeocodeResult.getRegeocodeAddress().getPois());
if (null != userSelectPoiItem) {
mList.add(0, userSelectPoiItem);
}
mAddressAdapter.setList(mList);
mRecyclerView.smoothScrollToPosition(0);
}
}
}
@Override
public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
}
};
// gps定位监听器
mAMapLocationListener = new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation loc) {
try {
if (null != loc) {
stopLocation();
if (loc.getErrorCode() == 0) {
// 可在其中解析amapLocation获取相应内容。
location = loc;
SPUtils.putString(GaoDeActivity.this, DatasKey.LOCATION_INFO, gson.toJson(location));
doWhenLocationSucess();
} else {
// 定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
Log.e("AmapError", "location Error, ErrCode:" + loc.getErrorCode() + ", errInfo:" + loc.getErrorInfo());
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
};
// recycleview列表监听器
mAddressAdapter.setOnItemClickLisenter(new OnItemClickLisenter() {
@Override
public void onItemClick(int position) {
try {
isSearchData = false;
mIvLocation.setImageResource(R.mipmap.location_gps_black);
moveMapCamera(mList.get(position).getLatLonPoint().getLatitude(), mList.get(position).getLatLonPoint().getLongitude());
refleshSelectByListMark(mList.get(position).getLatLonPoint().getLatitude(), mList.get(position).getLatLonPoint().getLongitude());
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
// 控件点击监听器
mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.iv_back:
finish();
break;
case R.id.iv_search:
// Toast.makeText(MainActivity.this, "搜索", Toast.LENGTH_SHORT).show();
startActivityForResult(new Intent(GaoDeActivity.this, SearchActivity.class), SEARCHREQUESTCODE);
break;
case R.id.iv_location:
// Toast.makeText(MainActivity.this, "定位", Toast.LENGTH_SHORT).show();
mIvLocation.setImageResource(R.mipmap.location_gps_green);
if (null != mSelectByListMarker) {
mSelectByListMarker.setVisible(false);
}
if (null == location) {
startLocation();
} else {
doWhenLocationSucess();
}
break;
case R.id.bt_send:
if (null != mList && 0 < mList.size() && null != mAddressAdapter) {
int position = mAddressAdapter.getSelectPositon();
if (position < 0) {
position = 0;
} else if (position > mList.size()) {
position = mList.size();
}
PoiItem poiItem = mList.get(position);
Toast.makeText(GaoDeActivity.this, "发送:" + poiItem.getTitle() + " " + poiItem.getSnippet() + " " + "纬度:" + poiItem.getLatLonPoint().getLatitude() + " " + "经度:" + poiItem.getLatLonPoint().getLongitude(), Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}
};
mIvBack.setOnClickListener(mOnClickListener);
mIvSearch.setOnClickListener(mOnClickListener);
mIvLocation.setOnClickListener(mOnClickListener);
mBtSend.setOnClickListener(mOnClickListener);
}
use of com.amap.api.services.geocoder.RegeocodeResult in project YourEyes by SevenLJY.
the class MyLocationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mylocation);
longitude = -1;
btn_getLocation = (Button) findViewById(R.id.btn_getLocation);
tv_location = (TextView) findViewById(R.id.tv_location);
et_destinationName = (EditText) findViewById(R.id.et_destinationName);
btn_toNavi = (Button) findViewById(R.id.btn_toNavi);
tv_destination = (TextView) findViewById(R.id.tv_destination);
dest_longitude = 0;
dest_latitude = 0;
//初始化定位和地址解析
initLocation();
search = new GeocodeSearch(this);
search.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {
@Override
public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {
// RegeocodeAddress addr = regeocodeResult.getRegeocodeAddress();
}
@Override
public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
GeocodeAddress addr = geocodeResult.getGeocodeAddressList().get(0);
LatLonPoint latlng = addr.getLatLonPoint();
dest_longitude = latlng.getLongitude();
dest_latitude = latlng.getLatitude();
String temp = "";
temp += "经度:" + dest_longitude + "\n";
temp += "纬度:" + dest_latitude + "\n";
tv_destination.setText(temp);
}
});
btn_getLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startLocation();
}
});
btn_toNavi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
destinationName = et_destinationName.getText().toString().trim();
if (destinationName.equals("")) {
ToastUtil.show(MyLocationActivity.this, "请输入有效地址");
} else {
if (city != null) {
GeocodeQuery query = new GeocodeQuery(destinationName, city);
search.getFromLocationNameAsyn(query);
}
}
}
});
}
Aggregations