Java 从编辑文本中获取地名并放置在地图上
可能重复:Java 从编辑文本中获取地名并放置在地图上,java,android,maps,dialog,Java,Android,Maps,Dialog,可能重复: 这是我从“警报”对话框中获取地名的代码,我想在地图上标记地名。你能帮我进一步做些什么吗?通过从这些表格中获取输入,在地图上标出位置。 AlertDialog.Builder dialog=新建AlertDialog.Builder(此); 对话框.setTitle(“输入位置”); 对话框.setView(布局) final EditText placeText=(EditText)layout.findViewById(R.id.strtplace); 最后一个字符串placeN
这是我从“警报”对话框中获取地名的代码,我想在地图上标记地名。你能帮我进一步做些什么吗?通过从这些表格中获取输入,在地图上标出位置。 AlertDialog.Builder dialog=新建AlertDialog.Builder(此); 对话框.setTitle(“输入位置”); 对话框.setView(布局)
final EditText placeText=(EditText)layout.findViewById(R.id.strtplace);
最后一个字符串placeName=placeText.getText().toString();
setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface对话框,int-id){
//TODO自动生成的方法存根
//如果用户未在字段中输入任何内容,则中断执行
if(placeName.compareTo(“”==0)
次数=5;
String[]optionArray=新字符串[numberOptions];
地理编码器gcoder=新的地理编码器(TravellogActivity.this);
试一试{
列表结果=gcoder.getFromLocationName(地名、数字选项);
迭代器位置=results.Iterator();
String raw=“\n原始字符串:\n”;
弦国;
int optcount=0;
while(locations.hasNext()){
地址位置=位置。下一步();
lat=位置。getLatitude();
lon=location.getLongitude();
country=location.getCountryName();
如果(国家==null){
国家=”;
}否则{
country=“,”+国家;
}
原始+=位置+“\n”;
optionArray[opCount]=location.getAddressLine(0)+“,“+location.getAddressLine(1)+国家+”\n”;
opCount++;
}
Log.i(“位置列表”,原始);
Log.i(“位置列表”,“选项:\n”);
对于(inti=0;i如果您想在地图顶部添加任何视图,您需要使用google提供的jar文件中定义的MapOverlay类
点击此链接。只需简单修改即可解决您的问题
final EditText placeText = (EditText)layout.findViewById(R.id.strtplace);
final String placeName = placeText.getText().toString();
dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// TODO Auto-generated method stub
//Break from execution if the user has not entered anything in the field
if(placeName.compareTo("")==0)
numberOptions = 5;
String [] optionArray = new String[numberOptions];
Geocoder gcoder = new Geocoder(TravellogActivity.this);
try{
List<Address> results = gcoder.getFromLocationName(placeName,numberOptions);
Iterator<Address> locations = results.iterator();
String raw = "\nRaw String:\n";
String country;
int opCount = 0;
while(locations.hasNext()){
Address location = locations.next();
lat = location.getLatitude();
lon = location.getLongitude();
country = location.getCountryName();
if(country == null) {
country = "";
} else {
country = ", "+country;
}
raw += location+"\n";
optionArray[opCount] = location.getAddressLine(0)+", "+location.getAddressLine(1)+country+"\n";
opCount ++;
}
Log.i("Location-List", raw);
Log.i("Location-List","\nOptions:\n");
for(int i=0; i<opCount; i++){
Log.i("Location-List","("+(i+1)+") "+optionArray[i]);
}
} catch (IOException e){
Log.e("Geocoder", "I/O Failure; is network available?",e);
}
// p = new GeoPoint((int)(latE6),(int)(lonE6));
}
});
dialog.show();
break;
}
return false ;
}