本文整理汇总了Java中com.amap.api.location.AMapLocation.getCity方法的典型用法代码示例。如果您正苦于以下问题:Java AMapLocation.getCity方法的具体用法?Java AMapLocation.getCity怎么用?Java AMapLocation.getCity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amap.api.location.AMapLocation
的用法示例。
在下文中一共展示了AMapLocation.getCity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCity
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
/**
* 设置当前城市
* @param amapLocation
*/
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void setCity(AMapLocation amapLocation) {
if(amapLocation!=null){
this.city = amapLocation.getCity();
}
}
示例2: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
/**
* 实现定位
* @param amapLocation
*/
@Override
public void onLocationChanged(AMapLocation amapLocation) {
if (mListener != null && amapLocation != null) {
if (amapLocation != null
&&amapLocation.getErrorCode() == 0) {
if(isFirstTime){//只要第一次的数据,当然,也可以在这里关闭定位
// mlocationClient.stopLocation();//停止定位
mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
lvHolder.title = "[位置]";
lvHolder.address = amapLocation.getProvider()+amapLocation.getCity()+amapLocation.getStreet()+amapLocation.getStreetNum();
lvHolder.lp = new LatLonPoint(amapLocation.getLatitude(),amapLocation.getLongitude());
mEndMarker.setPosition(new LatLng(amapLocation.getLatitude(),amapLocation.getLongitude()));
data.add(0,lvHolder);
doSearchQuery();
}
} else {
String errText = "定位失败," + amapLocation.getErrorCode()+ ": " + amapLocation.getErrorInfo();
Log.e("AmapErr",errText);
}
}
}
示例3: initLocation
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
/**
* 初始化百度地图
*/
private void initLocation() {
AMapLocation location = locationClient.getLastKnownLocation();
if (location != null) {
Log.d(TAG, "getLastKnownLocation success");
mLongitude = location.getLongitude();
mLatitude = location.getLatitude();
city = location.getCity();
country = location.getCountry();
Log.d("XLight", String.format("long:%s,latitude:%s,ciry:%s,country:%s", mLongitude, mLatitude, city, country));
//请求天气信息
updateLocationInfo();
} else {
// 启动定位
locationClient.startLocation();
}
}
示例4: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
@Override
public void onLocationChanged(AMapLocation loc) {
if (null != loc && loc.getErrorCode() == 0) {
//解析定位结果
mLongitude = loc.getLongitude();
mLatitude = loc.getLatitude();
city = loc.getCity();
country = loc.getCountry();
Log.i("XLight", String.format("long:%s,latitude:%s,city:%s,country:%s", mLongitude, mLatitude, city, country));
//请求天气信息
updateLocationInfo();
locationClient.stopLocation();
} else {
// 定位失败,显示提示
Log.e("XLight", "location Error, ErrCode:"
+ loc.getErrorCode() + ", errInfo:"
+ loc.getErrorInfo());
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ToastUtil.showToast(getActivity(), R.string.open_gps);
}
});
}
}
示例5: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
mCity = aMapLocation.getCity();
mSwipeRefreshLayout.setEnabled(true);
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
}
});
getWeatherData(mCity);
}
//定位失败,通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息
else {
SnackBarUtil.showSnackBar(aMapLocation.getErrorInfo(), mSwipeRefreshLayout, getActivity());
}
}
}
示例6: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
@Override
public void onLocationChanged(AMapLocation aLocation) {
if (aLocation != null) {
// mALocation = aLocation;
/**
* 获取城市的编码
*/
//cityCode = aLocation.getCityCode();
String city = aLocation.getCity();
if (!TextUtils.isEmpty(city)) {
datas.set(0, city);
mRouteAdapter.notifyDataSetChanged();
}
// StringBuffer sb = new StringBuffer(256);
// sb.append(aLocation.getCity());
// if (sb.toString() != null && sb.toString().length() > 0) {
// String lngCityName = sb.toString();
//
// }
}
}
示例7: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
@Override
public void onLocationChanged(AMapLocation aLocation) {
if (aLocation != null) {
// mALocation = aLocation;
/**
* 获取城市的编码
*/
//cityCode = aLocation.getCityCode();
String city = aLocation.getCity();
String add = aLocation.getPoiName();
//Log.i("TAG", "------>" + aLocation.getPoiName() + "--->" + aLocation.getDistrict() + "------>" + aLocation.getProvider());
if (!TextUtils.isEmpty(city) && !TextUtils.isEmpty(add)) {
mAddress.setText(city + " · " + add);
address = city + " · " + add;
}
// StringBuffer sb = new StringBuffer(256);
// sb.append(aLocation.getCity());
// if (sb.toString() != null && sb.toString().length() > 0) {
// String lngCityName = sb.toString();
//
// }
}
}
示例8: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
/**
* 定位成功后回调函数
*/
@Override
public void onLocationChanged(AMapLocation aLocation) {
if (mListener != null && aLocation != null) {
mALocation = aLocation;
/**
* 获取城市的编码
*/
cityCode = aLocation.getCityCode();
city = aLocation.getCity();
mListener.onLocationChanged(aLocation);// 显示系统小蓝点
//获取经纬度
BigDecimal latitude = new BigDecimal(aLocation.getLatitude());
x = latitude.setScale(8, BigDecimal.ROUND_DOWN).doubleValue();
BigDecimal longitude = new BigDecimal(aLocation.getLongitude());
y = longitude.setScale(8, BigDecimal.ROUND_DOWN).doubleValue();
//搜索框内容为空时执行周边搜索方法,有内容时执行关键词搜索方法
final String searchKey = mSearch.getText().toString().trim();
if (TextUtils.isEmpty(searchKey)) {
PoiCheckEnd(aLocation, "");
} else {
initListener();
}
}
}
示例9: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
/**
* 定位监听回掉
*/
@Override
public void onLocationChanged(AMapLocation amapLocation) {
if (mListener != null && amapLocation != null) {
if (amapLocation.getErrorCode() == 0) {
mCity = amapLocation.getCity();
mCityTextView.setText(mCity);
mPresenter.searchWeatherRecord(getContext(), amapLocation.getCity());
mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
} else {
String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
Log.e("AmapErr", errText);
//mLocationErrText.setVisibility(View.VISIBLE);
//mLocationErrText.setText(errText);
}
}
}
示例10: getLocationCityStr
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
/**
* 根据定位结果返回定位信息的字符串
*
* @param location
* @return
*/
public synchronized static String getLocationCityStr(AMapLocation location) {
if (null == location) {
return null;
}
StringBuffer sb = new StringBuffer();
//errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明
if (location.getErrorCode() == 0) {
String tmpSb = location.getCity();
sb.append(tmpSb.substring(0, tmpSb.length() - 1));
} else {
//定位失败
sb.append("定位失败" + "\n");
sb.append("错误码:" + location.getErrorCode() + "\n");
sb.append("错误信息:" + location.getErrorInfo() + "\n");
sb.append("错误描述:" + location.getLocationDetail() + "\n");
}
Log.d("AMapUtils", sb.toString());
return sb.toString();
}
示例11: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if (aMapLocation != null) {
if (aMapLocation.getErrorCode() == 0) {
presenter = new OnShownMoviePresenter(this, aMapLocation.getCity());
presenter.start();
} else {
presenter = new OnShownMoviePresenter(this,"杭州");
presenter.start();
ToastUtil.makeTextShort(getActivity(), getString(R.string.error_location) + " code:" + aMapLocation.getErrorCode()
+ " msg:" + aMapLocation.getErrorInfo());
}
}
}
示例12: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
@Override
public void onLocationChanged(AMapLocation amapLocation) {
if (amapLocation != null && amapLocation.getAMapException().getErrorCode() == 0) {
//获取位置信息
location = amapLocation.getAddress();
city = amapLocation.getProvince() + "·" + amapLocation.getCity() + amapLocation.getDistrict();
}
}
示例13: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
Message message = mHandler.obtainMessage();
message.obj = aMapLocation.getCity();
message.what = UPDATELOCATION_MESSAGE;
Log.e(TAG, "onLocationChanged: " + aMapLocation.getCity());
message.sendToTarget();
}
示例14: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
@Override
public void onLocationChanged(AMapLocation location) {
// this.location = location;
if (mListener != null && location != null) {
mListener.onLocationChanged(location);
}
if (!locationChange) {
if (location != null) {
LatLng latlng = new LatLng(location.getLatitude(),
location.getLongitude());
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latlng).zoom(18).build();
map.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
if (latlng != null) {
String keyWord = location.getCity();
PoiSearch.Query query = new PoiSearch.Query(
keyWord,
"汽车服务|汽车销售|汽车维修|摩托车服务|餐饮服务|购物服务|生活服务|体育休闲服务|医疗保健服务|风景名胜|商务住宅|政府机构及社会团体|科教文化服务|交通设施服务|金融保险服务|公司企业|道路附属设施|地名地址信息|公共设施",
"");// (第三个参数)这里可以传空字符串,空字符串代表全国在全国范围内进行搜索
query.setPageNum(1);
query.setPageSize(40);
PoiSearch poiSearch = new PoiSearch(getActivity(), query);
poiSearch.setBound(new SearchBound(new LatLonPoint(
latlng.latitude, latlng.longitude), 3000));
poiSearch.setOnPoiSearchListener(this);
poiSearch.searchPOIAsyn();
}
locationChange = true;
}
}
}
示例15: onLocationChanged
import com.amap.api.location.AMapLocation; //导入方法依赖的package包/类
@Override
public void onLocationChanged(AMapLocation location) {
if (location != null && location.getAMapException().getErrorCode() == 0) {
this.aMapLocation = location;// 判断超时机制
cityName = location.getCity();
String cityCode = location.getCityCode();
main_tv_zipcode.setText(cityName + "\n" + "电话区号" + cityCode);
} else {
Log.e("code", ""+location.getAMapException().getErrorCode());
Log.e("location", ""+(location == null));
main_tv_zipcode.setText("定位失败...");
}
}