Android Geocoder

发布时间:2010-10-23 阅读量:1844 来源: 发布人:

package com.hl;

import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.maps.MapActivity;
public class Geo extends MapActivity {
private EditText input;
private Button btn;
private TextView show;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
input = (EditText)findViewById(R.id.input);
btn = (Button)findViewById(R.id.btn);
show = (TextView)findViewById(R.id.show);

btn.setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
show.setText(performGeocode(input.getText().toString(), true));
}
});
}

private String performGeocode(final String in, final boolean isAddr) {
String result= null;
if (this.input != null) {
Geocoder geocoder = new Geocoder(this,Locale.CHINA);
if (isAddr) {
try {
List
addresses = geocoder.getFromLocationName(in,5);
if (addresses != null) {
result = addresses.get(0).toString();
}
} catch (IOException e) {
Toast.makeText(Geo.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
} else {
try {
String[] coords = in.split(",");
if ((coords != null) && (coords.length == 2)) {
List
addresses = geocoder.getFromLocation(
Double.parseDouble(coords[0]),
Double.parseDouble(coords[1]), 1);
result = addresses.get(0).toString();
}
} catch (IOException e) {
Toast.makeText(Geo.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
return result;
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
注意不要在android 8的模拟器上做测试,不然不能成功的!!
220x90
相关资讯
三星电子计划 2026Q2 出样 HBM4E 内存

三星电子计划 2026Q2 出样 HBM4E 内存

受美国限制措施影响,英伟达B300服务器在中国的售价已达100万美元!

中国对人工智能计算设备的强劲需求已使英伟达B300服务器的价格几乎翻了一番,达到每台约700万元人民币(100万美元)

Anthropic反超OpenAI!成全球最高AI估值独角兽

据知情人士透露,由前OpenAI高管创立的AI初创公司Anthropic正与投资者洽谈新一轮融资,目标估值高达9000亿美元

JDI启动美国先进显示制造基地评估

近日,日本显示面板企业JDI正式宣布,已启动在美国建设与运营先进显示面板制造基地的可行性评估,并同步研究向当地合作伙伴提供技术支持的潜在合作模式。

三星电子推出32英寸裸眼3D显示器,面向零售与展览空间灵活部署

三星电子正扩展其裸眼3D显示产品线,计划推出32英寸小型裸眼3D显示器(品牌Spatial Signage,型号SMHX)