本帖最后由 bblaopoJun 于 2014-09-12 10:15:01 编辑

解决方案 »

  1.   

    传递数据的话使用intent
    Intent intent = new Intent(context, XXX.class);
    intent.putExtra("XX",XX);
    startActivity(intent);
    至于设置坐标的话去看下百度地图的api把
      

  2.   

    谢谢 这个传递数据我会用 就是不知道怎么在地图里用
    在oncreate方法里面 //定义经纬度:安徽商贸职业技术学院
            GeoPoint geoPoint = new GeoPoint((int) (31.294468 * 1E6),
                    (int) (118.374291 * 1E6));
            //设置getPoint为中心点
    此设置之前 可以创建两个变量记录经纬度 默认值就是你的实际坐标 如果有传递过来经纬的话 就使用传递过来 没有 就是默认的
      

  3.   

    谢谢 这个传递数据我会用 就是不知道怎么在地图里用
    在oncreate方法里面 //定义经纬度:安徽商贸职业技术学院
            GeoPoint geoPoint = new GeoPoint((int) (31.294468 * 1E6),
                    (int) (118.374291 * 1E6));
            //设置getPoint为中心点
    此设置之前 可以创建两个变量记录经纬度 默认值就是你的实际坐标 如果有传递过来经纬的话 就使用传递过来 没有 就是默认的
    嗯嗯 谢谢 很好的思路
      

  4.   

    Intent 回传不就好了 把坐标传回来之后 重新设置 GeoPoint 再调用地图的refresh()函数刷新地图就行了
      

  5.   

    是的
    我已经用intent把值传过来了 而且也接收到了 但是不知道为什么没效果呢
    这是MainActivitypackage com.sun.maptransform;import android.app.Activity;
    import android.content.Intent;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuItem;
    //import android.view.Window;
    import android.widget.Toast;import com.baidu.mapapi.BMapManager;
    import com.baidu.mapapi.MKGeneralListener;
    import com.baidu.mapapi.map.ItemizedOverlay;
    import com.baidu.mapapi.map.MKEvent;
    import com.baidu.mapapi.map.MapController;
    import com.baidu.mapapi.map.MapView;
    import com.baidu.mapapi.map.OverlayItem;
    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.MKShareUrlResult;
    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 MainActivity extends Activity { // UI相关
    // private Button mBtnReverseGeoCode = null; // 将坐标反编码为地址
    // private Button mBtnGeoCode = null; // 将地址编码为坐标
    // 添加百度地图相关控件
    private MapView mMapView;
    private BMapManager mBMapManager;
    // 搜索相关
    private MKSearch mSearch = null; // 搜索模块,也可去掉地图模块独立使用
    // 地图控制控件:放大、缩小
    private MapController mMapController;
    // key
    private String keyString = "dA3pVSQ5CemdZRT9So1D13Mn"; @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /**
     * 使用地图sdk前需先初始化BMapManager,这个必须在setContentView()先初始化
     */
    mBMapManager = new BMapManager(this); // 加载key
    mBMapManager.init(keyString, new MKGeneralListener() { @Override
    public void onGetPermissionState(int iError) {
    // TODO Auto-generated method stub
    if (iError == MKEvent.ERROR_PERMISSION_DENIED) {
    Toast.makeText(MainActivity.this, "API KEY ERROR!",
    Toast.LENGTH_SHORT).show();
    }
    } @Override
    public void onGetNetworkState(int iError) {
    // TODO Auto-generated method stub
    if (iError == MKEvent.ERROR_NETWORK_CONNECT) {
    Toast.makeText(MainActivity.this, "NETWORK CONNECT ERROR",
    Toast.LENGTH_SHORT).show();
    System.out.println("NETWORK CONNECT ERROR");
    }
    }
    }); setContentView(R.layout.geocoder); mMapView = (MapView) findViewById(R.id.bmapView); // 显示内置缩放控件
    // 隐藏自带的地图缩放控件
    mMapView.setBuiltInZoomControls(true); // 隐藏百度地图LOGO
    mMapView.removeViewAt(1); // 显示交通地图
    // mMapView.setTraffic(true);
    // 显示卫星地图
    // mMapView.setSatellite(true); // 获取地图控制器
    mMapController = mMapView.getController(); // 设置地图是否响应点击事件
    mMapController.enableClick(true);
    // 设置地图缩放级别
    mMapController.setZoom(14); // if(mMapView.getZoomLevel() == mMapView.getMinZoomLevel()){
    // Toast.makeText(MainActivity.this, "最小", Toast.LENGTH_SHORT).show();
    // }
    // 初始化搜索模块,注册事件监听
    mSearch = new MKSearch(); /**
     * 接收SearchCity_Activity传来的值
     */
    Intent intentSearchCity = this.getIntent();
    Bundle bundleSearchCity = intentSearchCity.getExtras();
    if (bundleSearchCity != null) {
    // Geo搜索
    mSearch.geocode(bundleSearchCity.getString("SearchCity_city")
    .toString(),
    bundleSearchCity.getString("SearchCity_geocodekey")
    .toString());
    Log.i("SearchCity_city",
    bundleSearchCity.getString("SearchCity_city"));
    Log.i("SearchCity_geocodekey",
    bundleSearchCity.getString("SearchCity_geocodekey"));
    } mSearch.init(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(MainActivity.this, str, Toast.LENGTH_LONG)
    .show();
    return;
    }
    // 地图移动到该点
    mMapView.getController().animateTo(res.geoPt);
    if (res.type == MKAddrInfo.MK_GEOCODE) {
    // 地理编码:通过地址检索坐标点
    String strInfo = String.format("纬度:%f 经度:%f",
    res.geoPt.getLatitudeE6() / 1e6,
    res.geoPt.getLongitudeE6() / 1e6);
    Toast.makeText(MainActivity.this, strInfo,
    Toast.LENGTH_LONG).show();
    }
    if (res.type == MKAddrInfo.MK_REVERSEGEOCODE) {
    // 反地理编码:通过坐标点检索详细地址及周边poi
    String strInfo = res.strAddr;
    Toast.makeText(MainActivity.this, strInfo,
    Toast.LENGTH_LONG).show(); }
    // 生成ItemizedOverlay图层用来标注结果点
    ItemizedOverlay<OverlayItem> itemOverlay = new ItemizedOverlay<OverlayItem>(
    null, mMapView);
    // 生成Item
    OverlayItem item = new OverlayItem(res.geoPt, "", null);
    // 得到需要标在地图上的资源
    Drawable er = getResources().getDrawable(
    R.drawable.icon_f);
    // 为maker定义位置和边界
    er.setBounds(0, 0, er.getIntrinsicWidth(),
    er.getIntrinsicHeight());
    // 给item设置er
    item.setMarker(er);
    // 在图层上添加item
    itemOverlay.addItem(item); // 清除地图其他图层
    mMapView.getOverlays().clear();
    // 添加一个标注ItemizedOverlay图层
    mMapView.getOverlays().add(itemOverlay);
    // 执行刷新使生效
    mMapView.refresh();
    } public void onGetPoiResult(MKPoiResult res, int type, int error) { } public void onGetDrivingRouteResult(MKDrivingRouteResult res,
    int error) {
    } public void onGetTransitRouteResult(MKTransitRouteResult res,
    int error) {
    } public void onGetWalkingRouteResult(MKWalkingRouteResult res,
    int error) {
    } public void onGetBusDetailResult(MKBusLineResult result, int iError) {
    } @Override
    public void onGetSuggestionResult(MKSuggestionResult res, int arg1) {
    } @Override
    public void onGetShareUrlResult(MKShareUrlResult result, int type,
    int error) {
    // TODO Auto-generated method stub } }); // 定义经纬度:安徽商贸职业技术学院
    GeoPoint geoPoint = new GeoPoint((int) (31.224078 * 1E6),
    (int) (121.540419 * 1E6));
    // 设置getPoint为中心点
    mMapController.setCenter(geoPoint); } @Override
    protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    if (mBMapManager != null) {
    mBMapManager.destroy();
    mBMapManager = null;
    }
    } @Override
    protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    if (mBMapManager != null) {
    mBMapManager.start();
    }
    } @Override
    protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    if (mBMapManager != null) {
    mBMapManager.stop();
    }
    } @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    } @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
    // TODO Auto-generated method stub switch (item.getItemId()) { // 菜单功能列表选项
    case R.id.searchCity:
    Intent intent = new Intent(MainActivity.this, SearchCity.class);
    item.setIntent(intent);
    break; default:
    break;
    }
    return super.onMenuItemSelected(featureId, item);
    }
    }这是SearchCitypackage com.sun.maptransform;import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;public class SearchCity extends Activity implements OnClickListener { private EditText inputSearchCity_city;    //城市输入框
    private EditText inputSearchCity_geocodekey;    //详细地址输入框
    private Button btnSearchCity; @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.searchcity); inputSearchCity_city = (EditText) this
    .findViewById(R.id.inputSearchCity_city);
    inputSearchCity_geocodekey = (EditText) this
    .findViewById(R.id.inputSearchCity_geocodekey); btnSearchCity = (Button) this.findViewById(R.id.btnSearchCity);
    btnSearchCity.setOnClickListener(this);
    } @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    if (inputSearchCity_city.getText() != null
    || inputSearchCity_geocodekey.getText() != null) {
    Intent intentSearchCity = new Intent();
    intentSearchCity.setClass(SearchCity.this, MainActivity.class);
    Bundle bundleSearchCity = new Bundle();
    bundleSearchCity.putString("SearchCity_city", inputSearchCity_city
    .getText().toString());
    bundleSearchCity.putString("SearchCity_geocodekey",
    inputSearchCity_geocodekey.getText().toString());
    intentSearchCity.putExtras(bundleSearchCity);
    startActivity(intentSearchCity);
    } else {
    Toast.makeText(SearchCity.this, "请输入地址信息", Toast.LENGTH_SHORT)
    .show();
    }
    }
    }
      

  6.   

    上层楼SearchActivity中 36、37行贴错了是if (inputSearchCity_city.getText() != null
    && inputSearchCity_geocodekey.getText() != null)