Android Geocoder

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

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的模拟器上做测试,不然不能成功的!!
相关资讯
外交部回应:AMD愿付15%税款对华出口芯片

近期,美国芯片出口管制政策出现新的变数,美方以“有条件许可”替代全面禁令的管控模式引发行业高度关注。

重磅!国产CPU在5G基站项目实现批量应用,打破国外垄断

飞腾CPU成功中标中国移动5G扩皮基站集采8000片

任正非:AI的重点在于应用,算力过剩的时代一定会到来!

AI要真正产生出价值,需要全社会的协作,发挥各自的优势。

又下黑手!传美议员提出多个法案,限制对华出口先进AI芯片

该法案将阻止特朗普政府放松限制北京获取英伟达(NVDA.O)人工智能芯片的规定。