Android 通过地名获得经纬度并标识在地图上
2010-10-21 01:38:14 来源:WEB开发网// 获取MapView
map = (MapView) findViewById(R.id.map);
// 设置显示模式
map.setTraffic(true);
map.setSatellite(false);
map.setStreetView(true);
// 设置可以缩放
map.setBuiltInZoomControls(true);
List
addresses = null;try {
addresses = geo.getFromLocationName("江苏省苏州市寒山寺", 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(addresses.size() == 0) {
showDialog(ERROR_DIALOG);
GeoPoint geoBeijing = new GeoPoint(
(int) (39.906033* 1000000),
(int) (116.397700 * 1000000));
mapCon = map.getController();
mapCon.setCenter(geoBeijing);
mapCon.setZoom(4);
} else {
Address address = addresses.get(0);
// 设置初始地图的中心位置
GeoPoint geoPoint = new GeoPoint(
(int) (address.getLatitude() * 1000000),
(int) (address.getLongitude() * 1000000));
mapCon = map.getController();
mapCon.setCenter(geoPoint);
mapCon.setZoom(16);
List overlays = this.map.getOverlays();
overlays.add(new PositionOverlay(geoPoint, this, R.drawable.ic_red_pin));
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
protected Dialog onCreateDialog(int id) {
return new AlertDialog.Builder(this).setTitle("查询出错哦")
.setMessage("路名/地名出错,请重新输入!").create();
}
class PositionOverlay extends Overlay {
private GeoPoint geoPoint;
private Context context;
private int drawable;
public PositionOverlay(GeoPoint geoPoint, Context context, int drawable)
赞助商链接