WEB开发网
开发学院手机开发Android 开发 Android 通过地名获得经纬度并标识在地图上 阅读

Android 通过地名获得经纬度并标识在地图上

 2010-10-21 01:38:14 来源:WEB开发网   
核心提示:// 获取MapViewmap = (MapView) findViewById(R.id.map);// 设置显示模式map.setTraffic(true);map.setSatellite(false);map.setStreetView(true);// 设置可以缩放map.setBuiltInZoomCont

// 获取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)

上一页  1 2 3 4 5  下一页

Tags:Android 通过 地名

编辑录入:coldstar [复制链接] [打 印]
赞助商链接