当我输入我的地址时,我想得到一个地方的纬度和经度。我有一项以编程方式创建的自定义 dailog 的活动,它有地址字段,当我输入我的地址时,我需要获取纬度和对数。下面是我试图获取 lat 和 lng 详细信息的适配器代码
public void performAction(View v, final Activity activity) {
Context myContext = v.getContext();
PopUpMenu popUpMenu = (PopUpMenu) v.getTag();
String result = popUpMenu.getMenuName();
if (result != null
&& result.equalsIgnoreCase(myContext.getResources().getString(
R.string.addnewplace))) {
AttractionData attractionData = new AttractionData();
createDiloag(attractionData,activity.getResources().getString(R.string.addnewplace));
setgpsLocation();
}
public void setgpsLocation() {
final EditText address = new EditText(this.activity);
String addressText = address.getText().toString();
try {
final StringBuffer myAddress = new StringBuffer();
if(addressText!=null&&!addressText.trim().equals("")){
myAddress.append(addressText);
}
Geocoder gcd = new Geocoder(parentActivity, Locale.getDefault());
List<Address> addresses = gcd.getFromLocationName(addressText, 5);
if (addressList != null && addressList.size() > 0) {
Address location = addressList.get(0);
location.getLatitude();
location.getLongitude();
// int lat = (int) (addressList.get(0).getLatitude() * 1e6);
// int lng = (int) (addressList.get(0).getLongitude() * 1e6);
AttractionData attractionData = new AttractionData();
attractionData.setLatitude(location.getLatitude());
attractionData.setLongitude( location.getLongitude());
} catch (Exception e) {
Log.e(TAG, "Error", e);
}
}
我无法获得 lat lng 详细信息,不胜感激。