0

I want to use Baidu map in android app. Until now, I have managed to integrate Baidu map, but it is showing a static map for all Latitude and Longitude. What i have done so far is:

public class BaiduMapActivity extends AppCompatActivity{

    @SuppressWarnings("unused")
    private static final String LTAG = BaiduMapActivity.class.getSimpleName();
    private MapView mMapView;
    private BaiduMap mBaiduMap;
    // ********bejing**********
    double lat = 39.9167;
    double longi = 116.3833;

    double shanghaiLat = 31.2000;
    double shangaiLong = 121.5000;
    Context mContext = BaiduMapActivity.this;
    RoutePlanSearch mSearch = null; // 搜索模块,也可去掉地图模块独立使用
    RouteLine route = null;
    OverlayManager routeOverlay = null;
    boolean useDefaultIcon = false;
    private boolean canGetLocation;
    private double singaporeLat = 1.3000;
    private double singaporeLong = 103.8000;
    private double hongkongLat = 22.2783;
    private double hongkongLong = 114.1747;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SDKInitializer.initialize(getApplicationContext());
        setContentView(R.layout.activity_baidu_maps_layout);
        init();
        try {
            mBaiduMap = mMapView.getMap();
            mBaiduMap.setMyLocationEnabled(true);
            MyLocationData locData = new MyLocationData.Builder()

                    .direction(100).latitude(hongkongLat).longitude(hongkongLong).build();  
          //loads same map even if lat long are changed
            mBaiduMap.setMyLocationData(locData);

        }catch (Exception e){
            e.printStackTrace();

        }
    }


    private void init() {
        mMapView = (MapView) findViewById(R.id.baidu_mapview_id);
    }

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

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

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

}

How to load map for different lat long?

vard
  • 4,057
  • 2
  • 26
  • 46

1 Answers1

0

You should change this line:

MyLocationData locData = new MyLocationData.Builder().direction(100).latitude(hongkongLat).longitude(hongkongLong).build();

you can change your hongkongLat to your lat, and hongkongLong to a your long.

BUT one thing to notice is that Baidu Maps used a different lat/long system. They do provide API to translate "Google's lat/lng" to "Baidu's lat/lng". However, it is always easier to use Google Maps.

kaho
  • 4,746
  • 1
  • 16
  • 24