Search in sources :

Example 1 with GeocodeResult

use of com.amap.api.services.geocoder.GeocodeResult 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);
                }
            }
        }
    });
}
Also used : GeocodeAddress(com.amap.api.services.geocoder.GeocodeAddress) GeocodeSearch(com.amap.api.services.geocoder.GeocodeSearch) RegeocodeResult(com.amap.api.services.geocoder.RegeocodeResult) GeocodeResult(com.amap.api.services.geocoder.GeocodeResult) LatLonPoint(com.amap.api.services.core.LatLonPoint) TextView(android.widget.TextView) View(android.view.View) LatLonPoint(com.amap.api.services.core.LatLonPoint) GeocodeQuery(com.amap.api.services.geocoder.GeocodeQuery)

Aggregations

View (android.view.View)1 TextView (android.widget.TextView)1 LatLonPoint (com.amap.api.services.core.LatLonPoint)1 GeocodeAddress (com.amap.api.services.geocoder.GeocodeAddress)1 GeocodeQuery (com.amap.api.services.geocoder.GeocodeQuery)1 GeocodeResult (com.amap.api.services.geocoder.GeocodeResult)1 GeocodeSearch (com.amap.api.services.geocoder.GeocodeSearch)1 RegeocodeResult (com.amap.api.services.geocoder.RegeocodeResult)1