use of com.amap.api.services.core.LatLonPoint in project KL2 by jweihao.
the class GaoDeActivity method getAddressInfoByLatLong.
/**
* 通过经纬度获取当前地址详细信息,逆地址编码
*
* @param latitude
* @param longitude
*/
private void getAddressInfoByLatLong(double latitude, double longitude) {
GeocodeSearch geocodeSearch = new GeocodeSearch(this);
/*
point - 要进行逆地理编码的地理坐标点。
radius - 查找范围。默认值为1000,取值范围1-3000,单位米。
latLonType - 输入参数坐标类型。包含GPS坐标和高德坐标。 可以参考RegeocodeQuery.setLatLonType(String)
*/
RegeocodeQuery query = new RegeocodeQuery(new LatLonPoint(latitude, longitude), 3000, GeocodeSearch.AMAP);
geocodeSearch.getFromLocationAsyn(query);
geocodeSearch.setOnGeocodeSearchListener(mOnGeocodeSearchListener);
}
use of com.amap.api.services.core.LatLonPoint 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.core.LatLonPoint 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);
}
}
}
});
}
use of com.amap.api.services.core.LatLonPoint in project KL2 by jweihao.
the class GaoDeActivity method doWhenLocationSucess.
/**
* 当定位成功需要做的事情
*/
private void doWhenLocationSucess() {
isSearchData = false;
userSelectPoiItem = DataConversionUtils.changeToPoiItem(location);
doSearchQuery(true, "", location.getCity(), new LatLonPoint(location.getLatitude(), location.getLongitude()));
moveMapCamera(location.getLatitude(), location.getLongitude());
refleshLocationMark(location.getLatitude(), location.getLongitude());
}
use of com.amap.api.services.core.LatLonPoint in project KL2 by jweihao.
the class SearchActivity method initListener.
private void initListener() {
mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.iv_back:
finish();
break;
default:
break;
}
}
};
mIvBack.setOnClickListener(mOnClickListener);
mEtSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (null != editable) {
if (0 == editable.length()) {
// 没有输入则清空搜索记录
mList.clear();
mSearchAddressAdapter.setList(mList, "");
} else {
if (null != location) {
doSearchQuery(editable.toString(), location.getCity(), new LatLonPoint(location.getLatitude(), location.getLongitude()));
} else {
doSearchQuery(editable.toString(), "", null);
}
}
}
}
});
mOnItemClickLisenter = new OnItemClickLisenter() {
@Override
public void onItemClick(int position) {
PoiItem poiItem = mList.get(position);
if (null != poiItem) {
// 获取信息并回传上一页面
Intent intent = new Intent();
intent.putExtra(DatasKey.SEARCH_INFO, poiItem);
setResult(RESULT_OK, intent);
finish();
}
}
};
mSearchAddressAdapter.setOnItemClickLisenter(mOnItemClickLisenter);
mOnPoiSearchListener = new PoiSearch.OnPoiSearchListener() {
@Override
public void onPoiSearched(PoiResult result, int i) {
if (i == 1000) {
if (result != null && result.getQuery() != null) {
// 搜索poi的结果
if (result.getQuery().equals(mQuery)) {
// 是否是同一条
if (null != mList) {
mList.clear();
}
// 取得第一页的poiitem数据,页数从数字0开始
mList.addAll(result.getPois());
if (null != mSearchAddressAdapter) {
mSearchAddressAdapter.setList(mList, mEtSearch.getText().toString().trim());
mRecyclerView.smoothScrollToPosition(0);
}
}
}
}
}
@Override
public void onPoiItemSearched(PoiItem poiItem, int i) {
}
};
}
Aggregations