Android Geocoder

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

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的模拟器上做测试,不然不能成功的!!
相关资讯
盘点国产MCU在机器人领域面临的重大挑战!

未来的人形机器人需要在端侧运行更复杂的AI模型,这要求MCU不仅要有强大的通用处理能力,还需要集成专用的NPU或DSP高效运行AI推理任务。

五大展区惊艳亮相,高端买家齐聚申城:第106届中国电子展成行业风向标

11月5日,第106届中国电子展在上海新国际博览中心迎来开门红,首日吸引超万人次专业观众到场。展会以“创新强基 智造升级”为核心,联合特种电子与半导体专题展,聚焦国产替代与自主可控,通过企业生态矩阵展示、实战化产线联动及20余个重点买家团对接,凸显国产电子产业在高端化、智能化升级中的协同突破与样本价值。

破局“卡脖子”困局!国产MCU强势崛起,工业机器人伺服控制迎来中国“芯”时代

机器人关节的高速、高加速度运动,要求MCU能在极短时间内(微秒级)完成位置环、速度环、电流环的三闭环计算。

工业机器人“心脏”之战:伺服控制系统市场爆发,2025年谁主沉浮?

本文将深入剖析工业机器人伺服控制系统的市场现状、核心技术壁垒以及未来发展趋势

温度传感器怎么选?一文讲透5大主流类型特性与精准选型黄金法则

本文将深入剖析五大主流温度传感器的工作原理、核心特性。