我居然定位到了几内亚湾
package leo.wuhantong; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.widget.Toast; import com.baidu.location.BDLocation; import com.baidu.location.BDLocationListener; import com.baidu.location.LocationClient; import com.baidu.location.LocationClientOption; import com.baidu.mapapi.SDKInitializer; import com.baidu.mapapi.map.BaiduMap; import com.baidu.mapapi.map.MapStatusUpdate; import com.baidu.mapapi.map.MapStatusUpdateFactory; import com.baidu.mapapi.map.MapView; import com.baidu.mapapi.map.MyLocationConfiguration; import com.baidu.mapapi.map.MyLocationData; import com.baidu.mapapi.model.LatLng; /** * 地图导航页 */ public class MapActivity extends AppCompatActivity { //定义控件 private MapView mapView; private BaiduMap baiduMap; //定位的 private LocationClient client; private LocationListener locationListener; // private boolean isFristIn = true; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SDKInitializer.initialize(getApplicationContext()); setContentView(R.layout.activity_map); //初始化控件 initView(); //事件监听器 initEvent(); } private void initEvent() { client = new LocationClient(this); locationListener = new LocationListener(); client.registerLocationListener(locationListener); //设置location的一些必要配置 LocationClientOption option = new LocationClientOption(); //坐标类型 option.setCoorType("bd09ll"); // option.setIsNeedAddress(true); //返回当前位置 option.setOpenGps(true); //请求间隔时间 1秒 option.setScanSpan(1000); } private void initView() { mapView = (MapView) findViewById(R.id.baidu_mapview); baiduMap = mapView.getMap(); MapStatusUpdate factory = MapStatusUpdateFactory.zoomBy(15.0f); baiduMap.setMapStatus(factory); } @Override protected void onDestroy() { super.onDestroy(); //在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理 mapView.onDestroy(); } @Override protected void onResume() { super.onResume(); //在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理 mapView.onResume(); } private class LocationListener implements BDLocationListener { @Override public void onReceiveLocation(BDLocation bdLocation) { /** * MyLocationData data = new MyLocationData.Builder()// .direction(mCurrentX)// .accuracy(location.getRadius())// .latitude(location.getLatitude())// .longitude(location.getLongitude())// .build(); mBaiduMap.setMyLocationData(data); */ MyLocationData data = new MyLocationData.Builder()// .accuracy(bdLocation.getRadius())//方向 .latitude(bdLocation.getLatitude())//精度 .longitude(bdLocation.getLongitude())// .build(); baiduMap.setMyLocationData(data); // MyLocationConfiguration config=new MyLocationConfiguration(MyLocationConfiguration.LocationMode.COMPASS); if (isFristIn) { LatLng latLng = new LatLng(bdLocation.getLatitude(), bdLocation.getLongitude()); MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(latLng); baiduMap.animateMapStatus(msu); isFristIn = false; } } } @Override protected void onPause() { super.onPause(); //在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理 mapView.onPause(); } @Override protected void onStart() { super.onStart(); //开启定位的允许 baiduMap.setMyLocationEnabled(true); client.start(); } @Override protected void onStop() { super.onStop(); //关闭定位功能 baiduMap.setMyLocationEnabled(false); client.stop(); } /** * Toast * * @param str 吐司的文本 */ public void toast(String str) { Toast.makeText(MapActivity.this, str, Toast.LENGTH_SHORT).show(); } /** * Log * * @param log Log的文本 */ public void log(String log) { Log.i("TAG", log); } }
开始我还以为我的哪里错了,后来想想感觉不大可能,然后我把地图缩小了n倍,发现我已经到了几内亚湾,求助,代码贴上