2 coolzpw coolzpw 于 2014.10.26 17:27 提问

这是我在百度上找打demo 求解怎么加代码转换成城市位置阿 求解

package wonder.gzmap;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.LocationListener;
import com.baidu.mapapi.MKAddrInfo;
import com.baidu.mapapi.MKBusLineResult;
import com.baidu.mapapi.MKDrivingRouteResult;
import com.baidu.mapapi.MKEvent;
import com.baidu.mapapi.MKGeneralListener;
import com.baidu.mapapi.MKPoiResult;
import com.baidu.mapapi.MKSearch;
import com.baidu.mapapi.MKSearchListener;
import com.baidu.mapapi.MKTransitRouteResult;
import com.baidu.mapapi.MKWalkingRouteResult;
import com.baidu.mapapi.MapView;
import com.baidu.mapapi.MyLocationOverlay;

import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class GZBaiduMap_Location extends Activity {

private BMapManager mBMapMan = null;//地图引擎
private String mStrKey = "AA32BEB96E600C3E390A64E479BF91B2748877D6";
private static boolean m_bKeyRight = true;
private MKSearch mksearch;//查找
private double longitude,latitude;

private MapView mMapView = null;
private LocationListener mLocationListener = null;
private MyLocationOverlay mLocationOverlay = null;
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);




        // 注册定位事件
        mLocationListener = new LocationListener(){

            @Override
            public void onLocationChanged(Location location) {
                if(location != null){
                    String strLog = String.format("您当前的位置:\r\n" +
                            "纬度:%f\r\n" +
                            "经度:%f",
                            location.getLongitude(), location.getLatitude());
                      longitude =  location.getLongitude();  
                        latitude =  location.getLatitude(); 

                    TextView mainText = (TextView)findViewById(R.id.textview);
                    mainText.setText(strLog);
                    GeoPoint geponit=new GeoPoint((int)(longitude*1E6),(int)(latitude*1E6));

                    mksearch.reverseGeocode(geponit);
                    Log.i("cc","daddsads");
                }
            }
        };
        mBMapMan = new BMapManager(this);
        mBMapMan.init(this.mStrKey, new MyKeyListener());
        //mBMapMan.getLocationManager().setNotifyInternal(10, 5);
         mksearch = new MKSearch();  

        mBMapMan.start();
        mksearch.init(mBMapMan, new MySearchListener());
    }


    @Override
    protected void onPause() {

        mBMapMan.getLocationManager().removeUpdates(mLocationListener);
        mBMapMan.stop();
        super.onPause();
    }
    @Override
    protected void onResume() {

        mBMapMan.getLocationManager().requestLocationUpdates(mLocationListener);
        mBMapMan.start();
        super.onResume();
    }
    static class MyKeyListener implements MKGeneralListener{

        @Override
        public void onGetNetworkState(int arg0) {
            // TODO Auto-generated method stub
            System.out.println("net error");
        }

        @Override
        public void onGetPermissionState(int arg0) {
            // TODO Auto-generated method stub
            if (arg0==MKEvent.ERROR_PERMISSION_DENIED){
                System.out.println("key error");
                m_bKeyRight=false;
            }
        }

    }
    public class MySearchListener implements MKSearchListener{

        @Override
        public void onGetAddrResult(MKAddrInfo result, int arg1) {
            // TODO Auto-generated method stub
            //反地理编码:通过坐标点检索详细地址及周边poi


            if(result==null){
                Toast.makeText(GZBaiduMap_Location.this, "解析失败",
                    Toast.LENGTH_LONG).show();
            }
            else{
                String strInfo = result.strAddr;
                Toast.makeText(GZBaiduMap_Location.this, strInfo,
                        Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onGetBusDetailResult(MKBusLineResult arg0, int arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onGetDrivingRouteResult(MKDrivingRouteResult arg0,
                int arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onGetPoiResult(MKPoiResult result, int arg1, int arg2) {
            // TODO Auto-generated method stub

// if(result==null&&arg2!=0){
// Toast.makeText(getApplicationContext(), "解析失败", 1).show();
// return;
// }
// //查找到点大于0说明查成功
// if(result !=null&&result.getCurrentNumPois()>0){
// GeoPoint gepoint=result.getAllPoi().get(0).pt;
// String msg=result.getAllPoi().get(0).name;
// Toast.makeText(getApplicationContext(), msg, 0);
//

// }

        }


        @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

        }

}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!