在Fragment中使用地图
package baidumapsdk.demo.map;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import com.baidu.mapapi.map.BaiduMapOptions;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.SupportMapFragment;
import com.baidu.mapapi.model.LatLng;
import baidumapsdk.demo.R;
public class MapFragmentDemo extends FragmentActivity {
SupportMapFragment map;
// 测试的武汉大学的经纬度
private double lat = 30.541093;
private double Lng = 114.360734;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
// 地图状态的构建
MapStatus.Builder builder = new MapStatus.Builder();
LatLng p = new LatLng(lat,Lng);
builder.
target(p)
.overlook(-20)
.zoom(15f);
// 地图选项的构建
BaiduMapOptions bo = new BaiduMapOptions()
.mapStatus(builder.build())
.compassEnabled(false)
.zoomControlsEnabled(false)
.scaleControlEnabled(false);
// 创建地图
map = SupportMapFragment.newInstance(bo);
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction().add(R.id.map, map, "map_fragment").commit();
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
}
@Override
protected void onRestart() {
super.onRestart();
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
}