導航:首頁 > 操作系統 > 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百度地圖默認相關的資料

熱點內容
資治通鑒中華書局pdf 瀏覽:212
如何搭建伺服器和資料庫 瀏覽:537
論文app怎麼用 瀏覽:466
開源文件伺服器加密 瀏覽:588
哈利波特游戲選什麼伺服器 瀏覽:424
雲伺服器怎樣格式化 瀏覽:16
框架柱頂部箍筋加密區規范 瀏覽:169
pythonjson文件讀取 瀏覽:105
夢幻西遊源碼架設 瀏覽:123
抽煙有解壓效果嗎 瀏覽:827
由於加密數據錯誤這個會話將結束 瀏覽:832
javaproject運行 瀏覽:255
0經驗轉行單片機 瀏覽:638
什麼叫解壓縮下載的文件 瀏覽:862
什麼牌子的手機加密狗好用 瀏覽:536
程序員編程學習筆記 瀏覽:864
吃雞亞服怎麼選擇不了伺服器 瀏覽:658
數控設備宏程序編程 瀏覽:840
高速銑編程培訓 瀏覽:650
天正改命令 瀏覽:773