導航:首頁 > 操作系統 > android百度地圖默認

android百度地圖默認

發布時間:2023-06-07 16:05:41

android百度地圖api開發地圖顯示問題

試下下面的代碼:

java">packagecom.liufeng.map;
importandroid.graphics.drawable.Drawable;
importandroid.os.Bundle;
importcom..mapapi.BMapManager;
importcom..mapapi.GeoPoint;
importcom..mapapi.MapActivity;
importcom..mapapi.MapController;
importcom..mapapi.MapView;
publicclassMainActivity蠢拿跡extendsMapActivity{
privateBMapManagermapManager;
privateMapViewmapView;
;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//初始化MapActivity
mapManager=newBMapManager(getApplication());
//init方法的第一個參數需填入申請的APIKey
mapManager.init("",null);
super.initMapActivity(mapManager);
mapView=(MapView)findViewById(R.id.map_View);
//設置地圖模式為交通地圖
mapView.setTraffic(true);
//設置啟用內置的縮放控制項
mapView.setBuiltInZoomControls(true);
//用給定的經緯度構造一個GeoPoint(緯度,經度)
GeoPointpoint=newGeoPoint((int)(47.118440*1E6),(int)(87.493147*1E6));
//創建標記maker
Drawablemarker=this.getResources().getDrawable(R.drawable.iconmarka);
//為maker定義位置和帶並邊界
marker.setBounds(0,敏簡0,marker.getIntrinsicWidth(),marker.getIntrinsicHeight());
//取得地圖控制器對象,用於控制MapView
mapController=mapView.getController();
//設置地圖的中心
mapController.setCenter(point);
//設置地圖默認的縮放級別
mapController.setZoom(12);
}
@Override
(){
returnfalse;
}
@Override
protectedvoidonDestroy(){
if(mapManager!=null){
mapManager.destroy();
mapManager=null;
}
super.onDestroy();
}
@Override
protectedvoidonPause(){
if(mapManager!=null){
mapManager.stop();
}
super.onPause();
}
@Override
protectedvoidonResume(){
if(mapManager!=null){
mapManager.start();
}
super.onResume();
}
}

❷ Android開發中百度地圖的定位為什麼總是北京,不是自己的位置

給,對照一下
可能的問題:1.用虛擬機,虛擬機定位就是在北京。
2.手機(或虛擬機)是否開啟了GPS功能

------------------------------
public class MainActivity extends AppCompatActivity {

MapView mMapView = null;
private BaiMap mBaiDuMap;
public LocationClient mLocationClient;
// public BDLocationListener myListener = new MyLocationListener();
public MyLocationListener myListener = new MyLocationListener();
private BitmapDescriptor mCurrentMarker;
private MyLocationConfiguration.LocationMode mCurrentMode;

// 經緯度
private TextView tvJingDu;
// 緯度
private TextView tvWeiDu;
// 高度
private TextView tvGaoDu;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.activity_main);

// 經緯度TextView 初始化
tvJingDu = (TextView) findViewById(R.id.tv_jing_);
tvWeiDu = (TextView) findViewById(R.id.tv_wei_);
tvGaoDu = (TextView) findViewById(R.id.tv_gao_);

//===================================
// 普通模式
mCurrentMode = MyLocationConfiguration.LocationMode.COMPASS;

// TODO
// mCurrentMarker = BitmapDescriptorFactory.fromResource(R.drawable.dingwei);
mCurrentMarker = null;

// 找到地圖控制項
mMapView = (MapView) findViewById(R.id.bmapView);
mBaiDuMap = mMapView.getMap();// 獲取地圖

mBaiDuMap.setMapType(BaiMap.MAP_TYPE_NORMAL);// 設置地圖模式為普通模式

// 開啟定點陣圖層
mBaiDuMap.setMyLocationEnabled(true);
mLocationClient = new LocationClient(this); // 定位用到一個類
mLocationClient.registerLocationListener(myListener);// 注冊監聽

// TODO
mBaiDuMap.setMyLocationConfigeration(new MyLocationConfiguration(
mCurrentMode, true, mCurrentMarker, R.color.myBlue, Color.YELLOW
));

// LocationClientOption類用來設置SDK的位置方式
LocationClientOption option = new LocationClientOption();//以下是給定位設置參數
option.setOpenGps(true); // 打開gps
option.setCoorType("bd09ll"); // 設置坐標類型
option.setScanSpan(2000);
mLocationClient.setLocOption(option);
mLocationClient.start();

}

boolean isFirstLoc = true; // 是否首次定位

// 3.網路位置監聽
public class MyLocationListener implements BDLocationListener {

@Override
public void onReceiveLocation(BDLocation location) {
Log.i("監聽被執行了", "監聽被執行了");

if (location == null || mMapView == null) {
return;
}

// // 定位結果
// StringBuffer sb = new StringBuffer(256);
// StringBuffer sb1 = new StringBuffer(256);
// StringBuffer sb2 = new StringBuffer(256);
// // 經度
// String jd = sb.append(location.getLongitude()).toString();
// tvJingDu.setText("" + jd);
// Log.i("經度", "" + jd);
// // 緯度
// String wd = sb1.append(location.getLatitude()).toString();
// tvWeiDu.setText("" + sb1);
// Log.i("緯度", "" + wd);
//
// String gao = sb.append(location.getAltitude()).toString();
// tvGaoDu.setText("" + gao);
// 經度
double d1 = location.getLongitude();
String s1 = "" + d1;
tvWeiDu.setText(s1);
Log.i("經度", "" + s1);
// 緯度
double d2 = location.getLatitude();
Log.i("TGA", "d2" + d2);
String s2 = "" + d2;
tvJingDu.setText(s2);
Log.i("緯度", "" + s2);

MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
// 此處設置開發者獲取到的方向信息,順時針0-360
.direction(0).latitude(location.getLatitude())
.longitude(location.getLongitude()).build();
mBaiDuMap.setMyLocationData(locData);

if (isFirstLoc) {
isFirstLoc = false;
LatLng ll = new LatLng(location.getLatitude(),
location.getLongitude());
MapStatus.Builder builder = new MapStatus.Builder();
// 縮放的等級 12.0f
builder.target(ll).zoom(18.0f);
mBaiDuMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
}
Log.i("MyLocationListener被執行了!", "onReceiveLocation");

}

@Override
public void onConnectHotSpotMessage(String s, int i) {

}
}

// 結束方法

@Override
protected void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}

@Override
protected void onResume() {
super.onResume();
mMapView.onResume();
}

@Override
protected void onPause() {
super.onPause();
mMapView.onPause();
}
}

閱讀全文

與android百度地圖默認相關的資料

熱點內容
主角變身女收女的變百小說 瀏覽:758
粉筆教育app從哪裡看做過的題 瀏覽:391
app數據包在哪裡找到 瀏覽:923
百煉成仙綠帽改編1-11 瀏覽:107
女主和一對雙胞胎兄弟 瀏覽:437
刀劍神域小說TXT 瀏覽:1000
php獲取文件地址 瀏覽:578
linuxsed替換字元 瀏覽:413
如何填寫國家反詐中心app注冊使用 瀏覽:790
日本影視網站 瀏覽:933
伺服器點亮埠以後有什麼特徵 瀏覽:980
51單片機定時器pwm 瀏覽:685
民國修真 瀏覽:386
php數組作為參數傳遞 瀏覽:991
運行命令查ip 瀏覽:202
漲奶吃奶小說 瀏覽:340
股票十大戰法主圖指標源碼 瀏覽:702
查看網路的命令是什麼意思 瀏覽:589
《鬼吹燈》1-8全本txt 瀏覽:336
python繪圖兩個圓代碼 瀏覽:607