Java Code Examples for com.amap.api.location.AMapLocation#getProvince()

The following examples show how to use com.amap.api.location.AMapLocation#getProvince() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Location.java    From xmpp with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation amapLocation) {
    if (amapLocation != null && amapLocation.getAMapException().getErrorCode() == 0) {
        //获取位置信息
        location = amapLocation.getAddress();
        city = amapLocation.getProvince() + "·" + amapLocation.getCity() + amapLocation.getDistrict();

    }
}
 
Example 2
Source File: LocationModel.java    From Fishing with GNU General Public License v3.0 5 votes vote down vote up
private Location createLocation(AMapLocation aMapLocation){
    Location location = new Location();
    location.address = aMapLocation.getAddress();
    location.altitude = aMapLocation.getAltitude();
    location.latitude = aMapLocation.getLatitude();
    location.longitude = aMapLocation.getLongitude();
    location.city = aMapLocation.getCity();
    location.country = aMapLocation.getCountry();
    location.district = aMapLocation.getDistrict();
    location.province = aMapLocation.getProvince();
    location.regionCode = Integer.parseInt(aMapLocation.getAdCode());
    return location;
}
 
Example 3
Source File: FindMapAroundAty.java    From myapplication with Apache License 2.0 4 votes vote down vote up
@Override
public void onLocationChanged(AMapLocation amapLocation) {
    if (amapLocation != null) {
        if (amapLocation.getErrorCode() == 0) {
            //定位成功回调信息,设置相关消息
            amapLocation.getLocationType();//获取当前定位结果来源,如网络定位结果,详见官方定位类型表
            mLatitude = amapLocation.getLatitude();//获取纬度
            mLongitude = amapLocation.getLongitude();//获取经度
            amapLocation.getAccuracy();//获取精度信息
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = new Date(amapLocation.getTime());
            df.format(date);//定位时间
            amapLocation.getAddress();//地址,如果option中设置isNeedAddress为false,则没有此结果,网络定位结果中会有地址信息,GPS定位不返回地址信息。
            amapLocation.getCountry();//国家信息
            amapLocation.getProvince();//省信息
            mCity = amapLocation.getCity();//城市信息
            amapLocation.getDistrict();//城区信息
            amapLocation.getStreet();//街道信息
            amapLocation.getStreetNum();//街道门牌号信息
            amapLocation.getCityCode();//城市编码
            amapLocation.getAdCode();//地区编码

            titleCenterTv.setText(amapLocation.getCity());
            lp = new LatLonPoint(mLongitude, mLatitude);
            Log.i(LOG, ">>>>> " + mCity + ", " + mLongitude + ", " + mLatitude);

            // 如果不设置标志位,此时再拖动地图时,它会不断将地图移动到当前的位置
            if (isFirstLoc) {
                //设置缩放级别
                aMap.moveCamera(CameraUpdateFactory.zoomTo(17));
                //将地图移动到定位点
                aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude())));
                //点击定位按钮 能够将地图的中心移动到定位点
                mListener.onLocationChanged(amapLocation);
                //添加图钉
                mMarker = aMap.addMarker(getMarkerOptions(amapLocation));

                isFirstLoc = false;
            }

        } else {
            //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。
            Log.e("AmapError", "location Error, ErrCode:"
                    + amapLocation.getErrorCode() + ", errInfo:"
                    + amapLocation.getErrorInfo());

            Toast.makeText(FindMapAroundAty.this, "定位失败", Toast.LENGTH_LONG).show();
        }
    }
}