用com.baidu.mapapi.map相关函数
根据经纬度,找到地址信息(调用android地图百度API)
比如:给定一个坐标GeoPoint mylocation = new GeoPoint((int) (29.855 * 1E6),
(int) (114.345 * 1E6));//
有什么方法可以得到坐标对应的地址信息?求高手相助!多谢啦啦啦!
给出的地址信息要很详细,可以小到到一栋楼,比如"百度大厦".求指教,
急急急!在线等......Android百度地图经纬度 地址经纬度   

解决方案 »

  1.   

    GeoPoint mylocation = new GeoPoint((int) (29.855 * 1E6),
    (int) (114.345 * 1E6));
    Search.reverseGeocode(mylocation );返回结果在MKSearchListener里的onGetAddrResult方法通知
      

  2.   

    楼上:  这个不行啊,不够细致,只能够到一个地区,不能够到一座楼!package hu.sheng.jin;import android.app.Activity;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.os.Bundle;
    import android.os.Handler;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.FrameLayout;
    import android.widget.Toast;import com.baidu.location.BDLocation;
    import com.baidu.location.BDLocationListener;
    import com.baidu.location.BDNotifyListener;
    import com.baidu.location.LocationClient;
    import com.baidu.location.LocationClientOption;
    import com.baidu.mapapi.BMapManager;
    import com.baidu.mapapi.map.LocationData;
    import com.baidu.mapapi.map.MKMapViewListener;
    import com.baidu.mapapi.map.MapController;
    import com.baidu.mapapi.map.MapPoi;
    import com.baidu.mapapi.map.MapView;
    import com.baidu.mapapi.map.MyLocationOverlay;
    import com.baidu.mapapi.search.MKAddrInfo;
    import com.baidu.mapapi.search.MKBusLineResult;
    import com.baidu.mapapi.search.MKDrivingRouteResult;
    import com.baidu.mapapi.search.MKPoiResult;
    import com.baidu.mapapi.search.MKSearch;
    import com.baidu.mapapi.search.MKSearchListener;
    import com.baidu.mapapi.search.MKSuggestionResult;
    import com.baidu.mapapi.search.MKTransitRouteResult;
    import com.baidu.mapapi.search.MKWalkingRouteResult;
    import com.baidu.platform.comapi.basestruct.GeoPoint;public class LocationOverlayDemo extends Activity {
    static GeoPoint mylocation = new GeoPoint((int) (29.855 * 1E6),
    (int) (114.345 * 1E6));// 如果不给我位置的话默认为湖北科技学院图书馆
    static MapView mMapView = null;
    private MapController mMapController = null;
    public MKMapViewListener mMapListener = null;
    FrameLayout mMapViewContainer = null;
    // 定位相关
    LocationClient mLocClient;
    public MyLocationListenner myListener = new MyLocationListenner();
    public NotifyLister mNotifyer = null;
    Button testUpdateButton = null;
    Button NearbyButton = null;
    Button locationname = null;
    EditText indexText = null;
    MyLocationOverlay myLocationOverlay = null;
    int index = 0;
    static String nowlocatoinname=null;
    LocationData locData = null;
    DemoApplication app;
    Handler mHandler = new Handler() {
    public void handleMessage(android.os.Message msg) {
    Toast.makeText(LocationOverlayDemo.this, "定位成功!", Toast.LENGTH_SHORT)
    .show();
    };
    }; @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    app = (DemoApplication) this.getApplication();
    if (app.mBMapManager == null) {
    app.mBMapManager = new BMapManager(this);
    app.mBMapManager.init(DemoApplication.strKey,
    new DemoApplication.MyGeneralListener());
    }
    setContentView(R.layout.activity_locationoverlay);
    mMapView = (MapView) findViewById(R.id.bmapView);
    mMapController = mMapView.getController(); initMapView(); mLocClient = new LocationClient(this);
    mLocClient.registerLocationListener(myListener); LocationClientOption option = new LocationClientOption();
    option.setOpenGps(true);// 打开gps
    option.setCoorType("bd09ll"); // 设置坐标类型
    // option.setScanSpan(1000); //1秒钟扫描一次
    mLocClient.setLocOption(option);
    mLocClient.start();
    mMapView.getController().setZoom(17);
    mMapView.getController().enableClick(true); mMapView.setBuiltInZoomControls(true);
    mMapListener = new MKMapViewListener() { @Override
    public void onMapMoveFinish() {
    // TODO Auto-generated method stub
    } @Override
    public void onClickMapPoi(MapPoi mapPoiInfo) {
    // TODO Auto-generated method stub
    String title = "";
    if (mapPoiInfo != null) {
    title = mapPoiInfo.strText;
    mylocation = mapPoiInfo.geoPt;// 修改坐标
    Toast.makeText(LocationOverlayDemo.this, title,
    Toast.LENGTH_SHORT).show();
    }
    } @Override
    public void onGetCurrentMap(Bitmap b) {
    // TODO Auto-generated method stub
    } @Override
    public void onMapAnimationFinish() {
    // TODO Auto-generated method stub }
    };
    mMapView.regMapViewListener(DemoApplication.getInstance().mBMapManager,
    mMapListener);
    myLocationOverlay = new MyLocationOverlay(mMapView);
    locData = new LocationData();
    myLocationOverlay.setData(locData);
    mMapView.getOverlays().add(myLocationOverlay);
    myLocationOverlay.enableCompass();
    mMapView.refresh(); testUpdateButton = (Button) findViewById(R.id.button1);
    OnClickListener clickListener = new OnClickListener() {
    public void onClick(View v) {
    testUpdateClick();
    }
    };
    testUpdateButton.setOnClickListener(clickListener); NearbyButton = (Button) findViewById(R.id.button2);
    OnClickListener clickListener1 = new OnClickListener() {
    public void onClick(View v) {
    NearbySearch();
    }
    };
    NearbyButton.setOnClickListener(clickListener1);


    locationname = (Button) findViewById(R.id.button3); } protected void NearbySearch() {
    // TODO Auto-generated method stub
    Intent intent = new Intent();
    intent.setClass(LocationOverlayDemo.this, NearbyPoiSearch.class);
    this.startActivity(intent);
    } @Override
    protected void onPause() {
    mMapView.onPause();
    super.onPause();
    } @Override
    protected void onResume() {
    mMapView.onResume();
    super.onResume();
    } @Override
    protected void onDestroy() {
    if (mLocClient != null)
    mLocClient.stop();
    mMapView.destroy();
    DemoApplication app = (DemoApplication) this.getApplication();
    if (app.mBMapManager != null) {
    app.mBMapManager.destroy();
    app.mBMapManager = null;
    }
    super.onDestroy();
    } @Override
    protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mMapView.onSaveInstanceState(outState); } @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mMapView.onRestoreInstanceState(savedInstanceState);
    } public void testUpdateClick() {
    mLocClient.requestLocation();
    } private void initMapView() {
    mMapView.setLongClickable(true);
    // mMapController.setMapClickEnable(true);
    // mMapView.setSatellite(false);
    } @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
    } /**
     * 监听函数,又新位置的时候,格式化成字符串,输出到屏幕中
     */
    public class MyLocationListenner implements BDLocationListener {
    @Override
    public void onReceiveLocation(BDLocation location) {
    if (location == null)
    return;
    locData.latitude = location.getLatitude();
    locData.longitude = location.getLongitude();
    locData.accuracy = location.getRadius();
    locData.direction = location.getDerect();
    myLocationOverlay.setData(locData);
    mMapView.refresh();
    mylocation = new GeoPoint((int) (locData.latitude * 1e6),
    (int) (locData.longitude * 1e6));

    MapPoi mapPoiInfo=null;

    MKSearch mks = new MKSearch();
    mks.reverseGeocode(mylocation);
    mks.init(app.mBMapManager, new MKSearchListener() {
    @Override
    public void onGetPoiDetailSearchResult(int type, int error) {
    }
    public void onGetAddrResult(MKAddrInfo res, int error) {
    if (error != 0) {
    String str = String.format("错误号:%d", error);
    Toast.makeText(LocationOverlayDemo.this, str,
    Toast.LENGTH_LONG).show();
    return;
    }
    nowlocatoinname=res.strAddr;
    locationname.setText("你在"+nowlocatoinname);
    } @Override
    public void onGetBusDetailResult(MKBusLineResult arg0, int arg1) {
    // TODO Auto-generated method stub
    }
    @Override
    public void onGetDrivingRouteResult(MKDrivingRouteResult arg0,
    int arg1) { } @Override
    public void onGetPoiResult(MKPoiResult arg0, int arg1, int arg2) {
    } @Override
    public void onGetSuggestionResult(MKSuggestionResult arg0,
    int arg1) {
    // TODO Auto-generated method stub } @Override
    public void onGetTransitRouteResult(MKTransitRouteResult arg0,
    int arg1) {
    // TODO Auto-generated method stub } @Override
    public void onGetWalkingRouteResult(MKWalkingRouteResult arg0,
    int arg1) {
    // TODO Auto-generated method stub }
    }); mMapController.animateTo(mylocation, mHandler.obtainMessage(1));
    } public void onReceivePoi(BDLocation poiLocation) {
    if (poiLocation == null) {
    return;
    }
    } } public class NotifyLister extends BDNotifyListener {
    public void onNotify(BDLocation mlocation, float distance) {
    }
    }}
      

  3.   

    public void onGetAddrResult(MKAddrInfo res, int error) {
    if (error != 0) {
    String str = String.format("错误号:%d", error);
    Toast.makeText(LocationOverlayDemo.this, str,
    Toast.LENGTH_LONG).show();
    return;
    }
    你的这个函数就是 res是地址的详细信息
      

  4.   

    楼上你好:1.这个函数确实可以得到地址信息,但是呢这里打出来的地址是湖北省咸宁市咸安区s208,我希望的效果是湖北省咸宁市咸安区咸宁大道88号湖北科技学院图书馆;2.当我们点击地图的时候会触发
    public void onClickMapPoi(MapPoi mapPoiInfo) {
    // TODO Auto-generated method stub
    String title = "";
    if (mapPoiInfo != null) {
    title = mapPoiInfo.strText;
    mylocation = mapPoiInfo.geoPt;// 修改坐标
    Toast.makeText(LocationOverlayDemo.this, title,
    Toast.LENGTH_SHORT).show();
    }
    这个函数就可以打印出很小的一个地方,比如湖北科技学院图书馆;我想得到的就是这样的消息,我希望我定位成功后就把地图中心的位置自动打印出来,而不是我点击后才打印
      

  5.   


    public void onGetAddrResult(MKAddrInfo res, int error) {
    if (error != 0) {
    String str = String.format("错误号:%d", error);
    Toast.makeText(LocationOverlayDemo.this, str,
    Toast.LENGTH_LONG).show();
    return;
    }
    其实查询出来的是一条路线,我想要一个具体的坐标点,求指教啊
      

  6.   

    楼主的问题解决了没有啊?我最近也被这个问题困扰,就是得到经纬度后使用Geocoder或者通过访问百度主页返回地址的时候老是有误差啊!大概是500~600的误差!没法精确定位啊!求解救啊楼主!