Android: Baidu map development (super detailed)

Table of contents

1. Introduction to Baidu Maps

1. MapView class:

2. BaiduMap class:

3. GeoCoder class:

4.GeoCodeOption class:

5.GeoCodeResult class:

6. LocationClient类:

7.LocationClientOption 类:

8. RoutePlanSearch class:

9.LatLng class:

10. PoiSearch class: 

11.PoiResult class:

12.PoiInfo class:

13.PoiOverlay class:

14.MarkerOptions class:

15.MapStatusUpdate class:

2. Usage examples

Example 1: Get the current location:

 MainActivity :

 activity_main:

 AndroidManifest:

 operation result

1. Introduction to Baidu Maps

        Baidu Map SDK is a software development kit (SDK) for developers to integrate and use Baidu Map functions in Android applications. By using Baidu Map SDK, developers can display maps, obtain positioning information, search, navigate and other functions in their own applications.

        Baidu Map SDK provides many commonly used classes and methods for implementing various map-related functions. The following are some commonly used classes and their methods:

1. MapView class:

        The MapView class is a control class provided by Baidu Map SDK and is used to display maps on the application interface. It is a custom View that can be associated with the BaiduMap class to implement map display and interaction functions. 

  Commonly used methods: 

  •    getMap(): Get the instance of Baidu map object (BaiduMap).
  •    onResume(): Called in the Activity life cycle method to restore the drawing and positioning functions of the map control.
  •    onPause() : Called in the Activity life cycle method to pause the drawing and positioning functions of the map control.
  •    onDestroy(): Called in the Activity life cycle method to destroy the map control.

2. BaiduMap class:

        The BaiduMap class is the core class in Baidu Map SDK and is used to manage and operate maps. It provides a series of methods and interfaces for displaying maps, controlling map status, adding overlays, positioning and other functions. 

Commonly used methods:  

  •    setMapType(): Set the map display type, such as ordinary map, satellite map, etc.
  •    setMapStatus() : Set the status of the map, including center point coordinates, zoom level, tilt angle, rotation angle, etc.
  •    addOverlay(): Add overlay, such as marker, polyline, polygon, etc.
  •    clear(): Clears all overlays on the map.
  •    setOnMapClickListener(): Set the map click event listener.
  •    setOnMarkerClickListener(): Set the mark point click event listener.

3. GeoCoder class:

        The GeoCoder class is a geocoding and anti-geocoding tool class provided by Baidu Map SDK, which is used to convert address information and geographical coordinates. Through the GeoCoder class, developers can parse addresses into latitude and longitude coordinates (geocoding), or parse latitude and longitude coordinates into address information (reverse geocoding). 

Commonly used methods:  

  •    newInstance(): Create a GeoCoder instance.
  •    setOnGetGeoCodeResultListener(): Sets the geocoding query result listener.
  •    setOnGetReverseGeoCodeResultListener(): Sets the reverse geocoding query result listener.
  •    geocode(): Initiates a geocoding query to convert address information into latitude and longitude coordinates.
  •    reverseGeoCode(): Initiates a reverse geocoding query to convert latitude and longitude coordinates into address information.

4.GeoCodeOption class:

        The GeoCodeOption class is an option class in Baidu Map API, used to set geocoding parameters and options. Geocoding is the process of converting geographic locations into corresponding latitude and longitude coordinates.

Common methods

  • address(String address): Set the address information to be encoded.

  • city(String city): Set the city name where the address is located.

  • retCoordType(String coordType): Set the coordinate type of the returned result. Optional parameters include: "bd09ll" (Baidu coordinates, default value), "gcj02" (National Bureau of Statistics coordinates) and "wgs84" (WGS-84 coordinates).

  • getAddress(): Get the address information to be encoded.

  • getCity(): Get the city name where the address is located.

  • getRetCoordType(): Get the coordinate type of the returned result.

5.GeoCodeResult class:

        The GeoCodeResult class is a class used to represent geocoding results in Baidu Map API. Through this class, you can obtain geocoding query result information, including location coordinates, address description, etc. 

  • getLocation(): Get the geocoded location coordinates (LatLng object).
  • getAddress(): Get the address description of the geocoding result.
  • getBusinessCircle(): Get the name of the business district to which the geocoding result belongs.
  • getSematicDescription(): Get the semantic description information of the geocoding results, that is, a more detailed text description.

6. LocationClient类:

         The LocationClient class is the core class provided by Baidu Positioning SDK and is used to implement the device's positioning function. Through the LocationClient class, developers can obtain the current location information of the device, including latitude and longitude coordinates, speed, direction, etc.

Commonly used methods:  

  •    registerLocationListener(): Register a location listener.
  •    start(): Start positioning.
  •    stop(): Stop positioning.

7. LocationClientOptionClass:

  LocationClientOptionClass is a configuration class in Baidu Map Positioning SDK, used to set positioning-related parameters and options. By creatingLocationClientOptionobjects and configuring them appropriately, more precise and personalized positioning capabilities can be achieved.

Common methods

  • setLocationMode(LocationClientOption.LocationMode mode): Set positioning mode, including three modes:

    • Hight_Accuracy: High-precision mode, using both GPS and network positioning.
    • Battery_Saving: Low power consumption mode, only uses network positioning.
    • Device_Sensors: Only uses GPS positioning.
  • setCoorType(String coorType): Set the coordinate system type of the returned positioning result, including:

    • bd09ll: Baidu latitude and longitude coordinates (default).
    • gcj02: National Bureau of Surveying encrypted latitude and longitude coordinates.
    • bd09: Baidu Mercator coordinates.
  • setScanSpan(int scanSpan): Set the positioning interval time in milliseconds. The set value is only valid if it is greater than or equal to 1000ms.

  • setIsNeedAddress(boolean isNeedAddress): Set whether address information needs to be obtained. The default is false.

  • setOpenGps(boolean isOpenGps): Set whether to turn on GPS, the default is false.

  • setIsNeedLocationDescribe(boolean isNeedLocationDesc): Set whether location description information is required, the default is false.

  • setIsNeedLocationPoiList(boolean isNeedLocationPoiList): Set whether surrounding POI information is required, the default is false.

  • setIsIgnoreCacheException(boolean isIgnoreCacheException): Set whether to ignore exceptions when GPS positioning fails. The default is false.

  • setEnableSimulateGps(boolean enableSimulateGps): Set whether to allow simulated GPS location, the default is false.

8. RoutePlanSearch class:

        The RoutePlanSearch class is a route planning search class provided by Baidu Map SDK, which is used to implement route planning functions for different transportation modes. Through the RoutePlanSearch class, developers can plan routes for various transportation modes such as driving, walking, and public transportation based on the coordinates of the starting point and end point, and obtain detailed route information.

Commonly used methods:  

  •    setOnGetRoutePlanResultListener() : Set the route planning result listener.
  •    drivingSearch(): Initiate driving route planning.
  •    walkingSearch(): Initiate walking route planning.
  •    transitSearch(): Initiate bus route planning.

9.LatLng class:

        The LatLng class is a class provided by Baidu Map SDK that represents latitude and longitude coordinates. It is used to store longitude and latitude information for a geographical location and provides methods to get and set longitude and latitude values. 

Commonly used methods:  

  • latitude(): Get the latitude value.
  • longitude(): Get the longitude value.
  • equals(LatLng other): Determine whether the current LatLng object is equal to another LatLng object.
  • toString(): Returns the string representation of the LatLng object. 

10. PoiSearch class: 

        The PoiSearch class is a point of interest search class provided by Baidu Map SDK, which is used to implement the point of interest retrieval function on the map. Through the PoiSearch class, developers can search for points of interest based on keywords, geographical location and other conditions, and obtain relevant search results.

Commonly used methods:  

  •  newInstance(): Create PoiSearch instance.
  • searchInCity(PoiCitySearchOption option): Search for points of interest within the specified city. You need to create a PoiCitySearchOption object, set the city name, keywords and other parameters to be searched, and then call this method to search.
  • searchNearby(PoiNearbySearchOption option): Search for points of interest near the specified location. You need to create a PoiNearbySearchOption object, set the center point coordinates, search radius, keywords and other parameters, and then call this method to search.
  • searchInBound(PoiBoundSearchOption option): Search for points of interest within the specified rectangular area. You need to create a PoiBoundSearchOption object, set the coordinates of the lower left corner and upper right corner of the rectangular area, keywords and other parameters, and then call this method to search.
  • setOnGetPoiSearchResultListener(OnGetPoiSearchResultListener listener): Set a listener for point-of-interest search results. You need to implement the OnGetPoiSearchResultListener interface and register it with the PoiSearch object to receive callbacks for search results.
  • searchPoiDetail(PoiDetailSearchOption option): Get detailed information based on the UID of the point of interest. You need to create a PoiDetailSearchOption object, set the UID of the point of interest, and then call this method to query the details.
  • searchPoiIndoor(PoiIndoorOption option): Search for points of interest in indoor maps. You need to create a PoiIndoorOption object, set indoor ID, keywords and other parameters, and then call this method to search.
  • searchPoiPage(int pageNum): Load the next page of search results. pageNumYou need to specify the page number to be loaded, and achieve paged loading by setting the properties of the previous search option object .
  • destroy(): Destroy the PoiSearch object and release related resources.

11.PoiResult class:

        The PoiResult class is a class in Baidu Map SDK, used to represent the result set of point of interest search. It contains a set of point-of-interest data that meets the search criteria and provides related methods to obtain and manipulate this data.

  • getAllPoi(): Get all searched results.
  • error: Indicates the error code of the search results. 

12.PoiInfo class:

        The PoiInfo class is a class in Baidu Map SDK and is used to represent information about points of interest. It contains detailed information such as the name, address, latitude and longitude coordinates of points of interest, and provides related methods to obtain and operate these data. 

  • name: POI name.
  • address:POI address.

13.PoiOverlay class:

        The PoiOverlay class is a class in Baidu Map SDK, used to draw interest point annotation overlays on the map. It can display the point of interest data in PoiResult on the map, and provides some methods for customizing label styles and click event handling.

  • setData(): Set the searched POI data.
  • addToMap(): Add point of interest annotations to the map.
  • zoomToSpan(): Zoom the map to fit all points of interest.

14.MarkerOptions class:

        The MarkerOptions class is an options class in Baidu Map API, used to set the parameters and options of marker points (Marker). Marker points are icons used to identify a certain location on the map. They are often used to display points of interest, location annotations, etc. 

  • position(LatLng position): Set the latitude and longitude coordinates of the marker point.
  • icon(BitmapDescriptor icon): Set the icon resource of the mark point, which can be a local image, a remote image or a built-in icon style. BitmapDescriptorFactoryCreate an object using a class BitmapDescriptorand pass it in as a parameter.
  • zIndex(int zIndex): Set the stacking order of mark points. The larger the value, the higher it is.
  • perspective(boolean perspective): Set the perspective effect of the marker point, that is, the tilt angle. true means to enable the perspective effect, false means not to enable it.
  • draggable(boolean draggable): Set whether the marker point can be dragged. true means draggable, false means not draggable.
  • animateType(MarkerAnimateType animateType): Set the animation effect type of the marker point. You can use MarkerAnimateTypeconstant values ​​in enumeration classes, such as MarkerAnimateType.none, MarkerAnimateType.grow, MarkerAnimateType.jump, MarkerAnimateType.drop.
  • getIcon(): Get the icon resource of the marker point.
  • getPosition(): Get the latitude and longitude coordinates of the marker point.
  • getZIndex(): Get the stacking order of marker points.
  • isPerspective(): Determine whether the perspective effect is enabled on the marker point.
  • isDraggable(): Determine whether the marked point can be dragged.
  • getAnimateType(): Get the animation effect type of the marker point.

15.MapStatusUpdate class:

        The MapStatusUpdate class is a class used to set map status updates in Baidu Map API. Through this class, you can perform operations such as panning, zooming, and rotating the map. 

  • newLatLng(LatLng latLng): Create a map status update object with the specified longitude and latitude as the center point.
  • newLatLngBounds(LatLngBounds bounds): Create a map status update object with the specified longitude and latitude boundaries as the display range.
  • newMapStatus(MapStatus mapStatus): Create a map status update object based on the specified map status.
  • newLatLngZoom(LatLng latLng, float zoom): Create a map status update object with the specified longitude and latitude as the center point and the specified zoom level.
  • zoomTo(float zoom): Creates a map status update object that zooms the map to the specified level.
  • zoomBy(float amount):Creates a map status update object that increases (positive values) or decreases (negative values) the map zoom level according to the specified ratio.
  • rotate(float rotate): Create a map status update object that rotates the map clockwise at a specified angle.
  • overlook(float overlook): Create a map status update object that looks down on the map at a specified angle.
  • scrollBy(int offsetX, int offsetY): Create a map status update object offset from the center point of the map along the screen pixel coordinates.

2. Usage examples

Example 1: Get the current location:

 MainActivity :

package com.example.location;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
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.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.geocode.GeoCodeOption;
import com.baidu.mapapi.search.geocode.GeoCodeResult;
import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;

public class MainActivity extends AppCompatActivity {
    LocationClient mLocationClient;

    MapView mMapView;
    BaiduMap mBaiduMap;
    private Button select;
    private EditText editText;
    boolean isFirstLocate = true;
    boolean isFirstText = true;
    TextView tv_Lat; // 经度
    TextView tv_Lon; // 纬度
    TextView tv_Add; // 地址
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 初始化地图应用
        SDKInitializer.setAgreePrivacy(this.getApplicationContext(),true);
        LocationClient.setAgreePrivacy(true);
        SDKInitializer.initialize(this.getApplicationContext());
        setContentView(R.layout.activity_main);
        mMapView = findViewById(R.id.bmapView);
        mBaiduMap = mMapView.getMap();
        tv_Lat = findViewById(R.id.tv_Lat);
        tv_Lon = findViewById(R.id.tv_Lon);
        tv_Add = findViewById(R.id.tv_Add);
        select = findViewById(R.id.btn_search);
        editText = findViewById(R.id.address);
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)!= PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);
        }else {
            requestLocation();
        }

        select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String address = editText.getText().toString();
                if (address!=null){

                    searchGeoCode(address);
                }else {
                    Toast.makeText(MainActivity.this, "请输入地点", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode){
            case 1:
                if (grantResults[0]!=PackageManager.PERMISSION_GRANTED){
                    Toast.makeText(this, "没有定位权限!", Toast.LENGTH_SHORT).show();
                    finish();
                }else{
                        requestLocation();
                }
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    }

    private void requestLocation() {
         // 定位前初始化
        initLocation();
        // 发起定位
        mLocationClient.start();
    }

    private void initLocation() {
//        LocationClient.setAgreePrivacy(true);
        try {
            mLocationClient = new LocationClient(getApplicationContext());
            mLocationClient.registerLocationListener(new MyLocationListener());

            // 定位客户端操作
            LocationClientOption option = new LocationClientOption();
            // 设置扫描时间
            option.setScanSpan(1000);
            // 设置定位参数
            option.setCoorType("bd09ll"); // 设置坐标类型为百度经纬度
            option.setIsNeedAddress(true); // 设置需要获取地址信息
            // 设置定位模式
            option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
//            option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving);
//            option.setLocationMode(LocationClientOption.LocationMode.Device_Sensors);
            option.setIsNeedAddress(true); // 设置需要地址信息
            // 保存定位参数
            mLocationClient.setLocOption(option);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // 内部类,百度位置监听器
    private class MyLocationListener implements BDLocationListener{

        @Override
        public void onReceiveLocation(BDLocation bdLocation) {
            if (isFirstText){
                tv_Lat.setText(bdLocation.getLatitude()+"");
                tv_Lon.setText(bdLocation.getLongitude()+"");
                tv_Add.setText(bdLocation.getAddrStr());
                isFirstText = false;
            }
            // GPS 定位或网格定位时
            if (bdLocation.getLocType()==BDLocation.TypeGpsLocation||bdLocation.getLocType()==BDLocation.TypeNetWorkLocation){
                navigateTo(bdLocation);
            }
        }

        private void navigateTo(BDLocation bdLocation) {
            if (isFirstLocate){
                LatLng ll = new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude());
                MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(ll);
                // 以动画更新方式,实现对手势引起的地图状态的更新
                mBaiduMap.animateMapStatus(update);
                // 创建自定义标记
                BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.arrow_icon);
                MarkerOptions markerOptions = new MarkerOptions().position(ll).icon(bitmap).anchor(0.5f, 0.5f);
                mBaiduMap.addOverlay(markerOptions);

                isFirstLocate = false;
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mMapView.onResume();
    }
    // 实现检索地点功能
    private void searchGeoCode(String address) {
        mBaiduMap.clear(); // 清除标记点

        GeoCoder geoCoder = GeoCoder.newInstance();
        GeoCodeOption geoCodeOption = new GeoCodeOption();
        geoCodeOption.address(address);
        geoCodeOption.city(address);
        geoCoder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {
            @Override
            public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
                if (geoCodeResult == null || geoCodeResult.error != SearchResult.ERRORNO.NO_ERROR) {
                    Toast.makeText(MainActivity.this, "检索错误", Toast.LENGTH_SHORT).show();
                } else {
                    LatLng latLng = geoCodeResult.getLocation();
                    MarkerOptions markerOptions = new MarkerOptions()
                            .position(latLng)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow_icon));
                    mBaiduMap.addOverlay(markerOptions);
                    MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newLatLngZoom(latLng, 15);
                    tv_Lat.setText(" "+latLng.latitude); // 经度
                    tv_Lon.setText(" "+latLng.longitude); // 纬度

                    tv_Add.setText(geoCodeResult.getAddress()); // 地址
                    mBaiduMap.setMapStatus(mMapStatusUpdate);

                }
            }
            @Override
            public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
                if (reverseGeoCodeResult == null || reverseGeoCodeResult.error != SearchResult.ERRORNO.NO_ERROR) {
                    Toast.makeText(MainActivity.this, "获取地址信息失败", Toast.LENGTH_SHORT).show();
                } else {
                    String address = reverseGeoCodeResult.getAddress();
                    Toast.makeText(MainActivity.this, address, Toast.LENGTH_SHORT).show();
                }
            }
        });
        geoCoder.geocode(geoCodeOption);
    }

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

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

 activity_main:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#e0000000"
        >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="12dp"
            android:layout_marginTop="20dp"
            android:orientation="horizontal"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="纬度:"
                android:textColor="#ffffff"
                android:textSize="15dp"
                />
            <TextView
                android:id="@+id/tv_Lat"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffffff"
                android:textSize="15sp"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="12dp"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="经度:"
                android:textColor="#ffffff"
                android:textSize="15dp"
                />
            <TextView
                android:id="@+id/tv_Lon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffffff"
                android:textSize="15sp"
                />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="12dp"
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="地址:"
                android:textColor="#ffffff"
                android:textSize="15dp"
                />
            <TextView
                android:id="@+id/tv_Add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=""
                android:textColor="#ffffff"
                android:textSize="15sp"
                />
        </LinearLayout>
    </LinearLayout>
    <com.baidu.mapapi.map.MapView
        android:id="@+id/bmapView"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="8"
        android:clickable="true"/>
    <LinearLayout
        android:id="@+id/layout_search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="8dp"
        android:background="#FFFFFF"
        android:layout_alignParentBottom="true">

        <EditText
            android:id="@+id/address"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="输入地址"
            android:layout_weight="1" />

        <Button
            android:id="@+id/btn_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="搜索" />

    </LinearLayout>


</LinearLayout>

 AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.location">
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.UI"

        >
        <meta-data
            android:name="com.baidu.lbsapi.API_KEY"
            android:value="你的Key" />
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote">
        </service>
    </application>

</manifest>

 operation result:

To be continued. . .

Guess you like

Origin blog.csdn.net/A125679880/article/details/131984857