use of com.amap.api.services.geocoder.GeocodeQuery 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