您的位置:首页 > 其它

使用百度地图SDK 这是之前版本 现在的sdk v2-1-2使用方法完全改变

2013-06-28 16:17 513 查看
1、添加BMapApiDemoApp.java

2、AndroidManifest文件 application里添加 android:name=".ui.BMapApiDemoApp"

<application android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".ui.BMapApiDemoApp"
android:debuggable="true">


3、xml 布局文件里添加

<com.baidu.mapapi.MapView
android:id="@+id/MapViewStoreInfo"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:clickable="true"/>


4、java文件 继承MapActivity

override onPause、onResume、isRouteDisplayed等函数

5、初始化地图、添加标记物

private void initMap() {
app = (BMapApiDemoApp) this.getApplication();
if (app.mBMapMan == null) {
app.mBMapMan = new BMapManager(getApplication());
app.mBMapMan.init(app.mStrKey,
new BMapApiDemoApp.MyGeneralListener());
}
app.mBMapMan.start();
// 如果使用地图SDK,请初始化地图Activity
super.initMapActivity(app.mBMapMan);

MapViewStoreInfo.getController().setCenter(setMapCenter());
marker = getResources().getDrawable(
R.drawable.map_marker); // 得到需要标在地图上的资源
marker.setBounds(0, 0, marker.getIntrinsicWidth(),
marker.getIntrinsicHeight()); // 为maker定义位置和边界

MapViewStoreInfo.getOverlays().clear();
MapViewStoreInfo.getOverlays().add(
new OverItemT(marker,StoreInfoActivity.this,setMapCenter()));
MapViewStoreInfo.invalidate();
}


6、下方添加标记物类

class OverItemT extends ItemizedOverlay<OverlayItem>{
private List<OverlayItem> mGeoList = new ArrayList<OverlayItem>();

public OverItemT(Drawable marker, Context context, GeoPoint pt) {
super(boundCenterBottom(marker));

mGeoList.add(new OverlayItem(pt, "", null));

populate();
}

@Override
protected OverlayItem createItem(int i) {
return mGeoList.get(i);
}

@Override
public int size() {
return mGeoList.size();
}

@Override
public boolean onSnapToItem(int i, int j, Point point, MapView mapview) {
Log.e("ItemizedOverlayDemo","enter onSnapToItem()!");
return false;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: