Baidu map API, which specifies the scale

Source: Internet
Author: User

Baidu map API, which specifies the scale

When Baidu maps are automatically located, the default scale is 5 kilometers. However, this range is too large to meet application requirements. You need to specify the scale when positioning. Finally, the solution was found through exploration and query.

Add the following code to the locating listener,

Float f = mBaiduMap. getMaxZoomLevel (); // 19.0 min Scale
// Float m = mBaiduMap. getMinZoomLevel (); // 3.0 maximum scale
MapStatusUpdate u = MapStatusUpdateFactory. newLatLngZoom (ll, F-2); // set the size to 100 meters

Overall code:

/**
* Locate the SDK listener Function
*/
Protected class MyLocationListenner implements BDLocationListener {


@ Override
Public void onReceiveLocation (BDLocation location ){
// After map view is destroyed, it is not processed in the new receiving location
If (location = null | mMapView = null)
Return;
MyLocationData locData = new MyLocationData. Builder ()
. Accuracy (location. getRadius () // set the direction information obtained by the developer, Which is 0-360 clockwise.
. Direction (100). latitude (location. getLatitude ())
. Longpolling (location. getlongpolling (). build ();
MBaiduMap. setMyLocationData (locData );
LatLng ll = new LatLng (location. getLatitude (),
Location. getlongpolling ());
Float f = mBaiduMap. getMaxZoomLevel (); // 19.0
// Float m = mBaiduMap. getMinZoomLevel (); // 3.0
MapStatusUpdate u = MapStatusUpdateFactory. newLatLngZoom (ll, F-2 );
MBaiduMap. animateMapStatus (u );
}


Public void onReceivePoi (BDLocation poiLocation ){

}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.