当前位置:网站首页>Baidu map, Gaode map, Tencent map Trinity map positioning development
Baidu map, Gaode map, Tencent map Trinity map positioning development
2022-07-22 03:17:00 【nanjumufeng】
1、 Development background
2、 development environment
2.1 Basic development environment
2.2 Baidu map environment
2.3 Gaode Map Environment
2.4 Tencent map environment
3、 Engineering configuration
3.1 add to jar package
3.2 add to so file
3.3 AndroidMainfest.xml To configure
4. Baidu map and positioning
5. Gaode map and positioning
6. Tencent map and positioning
1、 Development background
Because the company is developing Android projects , Positioning function is needed , So we need to choose a map with high positioning accuracy SDK. Now integrate the three most widely used map services in the market into one APP On , Realize Baidu map 、 Gould map 、 Tencent map comparison . Now the whole development steps are recorded .
2、 development environment
2.1 Basic development environment
AndroidStudio 3.4.2
Gradle Version:gradle-5.1.1-all.zip
Gradle plug-in:3.4.2
2.2 Baidu map environment
Baidu map developers open platform links : Official website
Baidu basic map SDK Download address : Download address
Baidu map positioning SDK Download address : Download address
Baidu map development jar package :BaiduLBS_Android.jar
Baidu map development so file :
liblocSDK7b.so
libBaiduMapSDK_base_v5_2_1.so
libBaiduMapSDK_map_v5_2_1.so
2.3 Gaode Map Environment
Gaud open platform : Official website
Gaode basic map SDK: Download address
Gaud map positioning SDK: Download address
Gaode map development jar package :
AMap_Location_V4.7.0_20190708.jar
Android_Map3D_SDK_V6.9.2_20190709.jar
Gaode map development so file : Unwanted
2.4 Tencent map environment
Tencent open platform : Official website
Tencent basic map SDK: Download address
Tencent map positioning SDK: Download address
Tencent map development jar package :
tencent-mapsdk-library-MainRelease-4.2.5.15519d1.jar
TencentLocationSdk_v7.1.7_r02c4bb5a_20190523_115148.jar
Tencent map development so file :
libtencentloc.so
libtxmapengine.so
3、 Engineering configuration
3.1 add to jar package
Use AndroidStudio Create a new project . And then I'll download jar copy to libs Under the table of contents .
after File->Project Structure
Click on + Number , choice jar Dependency.
add to libs Under the jar package . after ,OK.
stay app In the catalog build.gradle You can see the added content in .
3.2 add to so file
stay main Under the table of contents , Create a new folder jniLibs.
Will download so File copy to jniLibs In the folder .
Here we are , The environment on which the development depends is ready .
3.3 AndroidMainfest.xml To configure
Map development requires the permission of the mobile phone , stay xml Add the following permissions to the file .
<!-- Baidu positioning Authority -->
<!-- This permission is used for network location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- This permission is used to access GPS location -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Used to access the wifi Internet Information ,wifi Information will be used for network location -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Access to operator information , It is used to support the interface related to providing operator information -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- This permission is used to obtain wifi Access to ,wifi Information will be used for network location -->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- Write to extended storage , Write data to expansion card , Used to write offline positioning data -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Access the network , Network positioning needs Internet access -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Gaode locates other permissions -->
<!-- Used to read the current status of the phone -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- Write to extended storage , Write data to expansion card , Used to write cache location data -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Used to apply for calling A-GPS modular -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<!-- It is used to apply for obtaining Bluetooth information for indoor positioning -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<!-- Tencent locates other permissions -->
<!-- Changes in access to the Internet , Need some information for network location -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
Add the development secret key applied in the three development platforms .
So far, the basic environment of development has been completed .
4. Baidu map and positioning
In Baidu map xml Add... To the file MapView Control
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
stay BaiduActivity.java Code in .
Add compass 、 Scale and other controls
public void mapSetting(){
if(mBaiduMap==null){
mBaiduMap=mBaiduMapView.getMap();
UiSettings settings=mBaiduMap.getUiSettings();// Set the display positioning button , And you can click
//aMap.setLocationSource(this);// Set the location monitoring , Realize here LocationSource Interface
settings.setCompassEnabled(true);// Add compass
mBaiduMap.setMyLocationEnabled(true);
}
}
Open the method of positioning
private void baiDuLocation() {
// Locate the client of the service . The host program declares this class on the client , And call , Currently, it only supports starting in the main thread
LocationClient locationClient = new LocationClient(getApplicationContext());
// Statement LocationClient Class instance and configure positioning parameters
LocationClientOption locationOption = new LocationClientOption();
MyLocationListener myLocationListener = new MyLocationListener();
// Register listening function
locationClient.registerLocationListener(myLocationListener);
// Optional , Default high precision , Set positioning mode , High precision , low power consumption , Device only
locationOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
// Optional , Default gcj02, Set the coordinate system of the returned positioning result , If used with Baidu map , Recommended setting is bd09ll;
locationOption.setCoorType("bd09ll");
// Optional , Default 0, That is to say, only once , Set the interval between sending continuous positioning requests to be greater than or equal to 1000ms That's what works
locationOption.setScanSpan(1000);
// Optional , Set whether address information is required , By default, you don't need
locationOption.setIsNeedAddress(true);
// Optional , Set whether address description is required
locationOption.setIsNeedLocationDescribe(true);
// Optional , Set whether the device direction result is required
locationOption.setNeedDeviceDirect(false);
// Optional , Default false, Set if gps When valid, follow 1S1 Secondary frequency output GPS result
locationOption.setLocationNotify(true);
// Optional , Default true, location SDK Inside is a SERVICE, And put it in an independent process , Is the setting stop Kill the process while you're in the process , Default not to kill
locationOption.setIgnoreKillProcess(true);
// Optional , Default false, Set whether location semantic results are required , Can be in BDLocation.getLocationDescribe Get in , The result is similar to “ It's near Tiananmen in Beijing ”
locationOption.setIsNeedLocationDescribe(true);
// Optional , Default false, Set whether you need POI result , Can be in BDLocation.getPoiList Get in
locationOption.setIsNeedLocationPoiList(true);
// Optional , Default false, Set whether to collect CRASH Information , Default collection
locationOption.SetIgnoreCacheException(false);
// Optional , Default false, Set whether to turn on Gps location
locationOption.setOpenGps(true);
// Optional , Default false, Whether altitude information is required for positioning , By default, you don't need , All versions are available except the basic positioning version
locationOption.setIsNeedAltitude(false);
// Set to turn on the automatic callback position mode , When the switch is turned on , During this period, just locate SDK If you detect a location change, you will actively call back to the developer , In this mode, developers no longer need to care about the positioning interval , location SDK If you find that the location changes, you will call back to the developer in time
locationOption.setOpenAutoNotifyMode();
// Set to turn on the automatic callback position mode , When the switch is turned on , During this period, just locate SDK If you detect a location change, you will actively call back to the developer
locationOption.setOpenAutoNotifyMode(3000,1, LocationClientOption.LOC_SENSITIVITY_HIGHT);
// The LocationClientOption object , adopt setLocOption Methods are passed to LocationClient Object use
locationClient.setLocOption(locationOption);
// Start positioning
locationClient.start();
}
How to move the positioning window
public void moveTo(double lat,double lon){
LatLng cenpt=new LatLng(lat,lon);
MapStatus mMapStatus=new MapStatus.Builder().target(cenpt)
.zoom(17)
.build();
// Definition MapStatusUpdate object , To describe the changes that will take place in the map state
MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
// Change the map state
mBaiduMap.setMapStatus(mMapStatusUpdate);
BitmapDescriptor bitmap= BitmapDescriptorFactory.fromResource(R.mipmap.ic_location);
OverlayOptions option = new MarkerOptions()
.position(cenpt)
.icon(bitmap);
mBaiduMap.addOverlay(option);
}
5. Gaode map and positioning
In Gaode map xml Add... To the file MapView
<com.amap.api.maps.MapView
android:id="@+id/gaodemap"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.amap.api.maps.MapView>
Set compass 、 Scale, etc
public void mapSetting(){
if(aMap==null){
aMap=mGaodeMaoView.getMap();
UiSettings settings=aMap.getUiSettings();// Set the display positioning button , And you can click
//aMap.setLocationSource(this);// Set the location monitoring , Realize here LocationSource Interface
settings.setCompassEnabled(true);// Add compass
settings.setMyLocationButtonEnabled(true);
aMap.getCameraPosition();// Method can obtain the rotation angle of the map
settings.setLogoPosition(AMapOptions.LOGO_POSITION_BOTTOM_LEFT);// Set up LOGO
settings.setScaleControlsEnabled(true);// Set the scale
aMap.setMyLocationEnabled(true);
}
}
Open positioning method
private void gaoDeLocation() {
mLocationClient=new AMapLocationClient(getApplicationContext());// Initialize positioning
mLocationClient.setLocationListener(mLocationListener);// Set location callback listening
mLocationOption=new AMapLocationClientOption();// initialization AMapLocationClientOption object mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);// Select positioning mode
mLocationOption.setOnceLocation(false);// Get multiple positioning
mLocationOption.setOnceLocationLatest(true);// obtain 3S The first positioning with the highest internal accuracy
mLocationOption.setInterval(2000);// Set the positioning interval
mLocationOption.setNeedAddress(true);// Set whether to return address information
mLocationOption.setMockEnable(true);// Sets whether analog locations are allowed
mLocationOption.setHttpTimeOut(20000);// Set positioning timeout
mLocationClient.setLocationOption(mLocationOption);// Set the location parameters for the location client
mLocationClient.startLocation();// Start positioning
}
Monitor callback methods
public AMapLocationListener mLocationListener=new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
if(aMapLocation !=null){
if(aMapLocation.getErrorCode()==0){
aMapLocation.getLocationType();// Get the source of the current positioning result
double lat=aMapLocation.getLatitude();// Get latitude
double lon=aMapLocation.getLongitude();// Get longitude
float accuracy=aMapLocation.getAccuracy();// Get accuracy information
String adress=aMapLocation.getAddress();// Address , If option Set in isNeedAddress by false, There is no such result , There will be address information in the network location results ,GPS Location does not return address information .
String country=aMapLocation.getCountry();// National Information
String province=aMapLocation.getProvince();// Save information
String city=aMapLocation.getCity();// City Information
String district=aMapLocation.getDistrict();// City Information
String street=aMapLocation.getStreet();// Street information
String streetNum=aMapLocation.getStreetNum();// Street number information
String cityCode=aMapLocation.getCityCode();// City Code
String adCode=aMapLocation.getAdCode();// Area code
String aoiName=aMapLocation.getAoiName();// Gets the of the current anchor point AOI Information
String buildingId=aMapLocation.getBuildingId();// Get the current indoor location of the building Id
String floor=aMapLocation.getFloor();// Get the floor of the current indoor location
int gpsAccuracyStatus=aMapLocation.getGpsAccuracyStatus();// obtain GPS Current state
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// Get location time
Date date = new Date(aMapLocation.getTime());
String dt=df.format(date);
String add=adress+country+province+city+district+street+streetNum;
loc_gaode.setText(" Gaud positioning : latitude :"+lat+"|"+" longitude :"+lon+"|"+" precision :"+accuracy+"|"+" Address information :"+add+" At present GPS state :"+gpsAccuracyStatus+"|"+" Location time :"+dt);
if(isFirstLoc){
MyLocationStyle myLocationStyle=new MyLocationStyle();// Initialize the positioning small blue dot style
myLocationStyle.interval(1000);
myLocationStyle.showMyLocation(true);
aMap.setMyLocationStyle(myLocationStyle);// Set the location of the blue dot style
aMap.setMyLocationEnabled(true);// The setting indicates that the blue dot is displayed at startup
aMap.moveCamera(CameraUpdateFactory.zoomTo(zoomlevel));// Set zoom level
aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(aMapLocation.getLatitude(),aMapLocation.getLongitude())));// Move the map to the anchor point
mListener.onLocationChanged(aMapLocation);// Click button , It can move the center of the map to the positioning point
isFirstLoc=false;
}
}else{
// seek failed , It can be done by ErrCode The reason for the failure of code information determination
Log.e("AmapError","Location Error,Error:"
+aMapLocation.getErrorCode()
+",errInfo:"+aMapLocation.getErrorInfo());
}
}
}
};
6. Tencent map and positioning
On Tencent map xml Add... To the file MapView
<com.tencent.tencentmap.mapsdk.maps.MapView
android:id="@+id/tencentMap"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Add compass 、 Scale and other controls
public void userSetting(){
tencentMap.setMapStyle(TencentMap.MAP_TYPE_NORMAL);// Set the type of display map : Ordinary 、 satellite 、 Live traffic
UiSettings mysetting=tencentMap.getUiSettings();
mysetting.setZoomControlsEnabled(true);// Set zoom in and zoom out
mysetting.setCompassEnabled(true);// Turn on the compass
tencentMap.setMyLocationEnabled(true);
}
Turn on Positioning
public void tencentLocation(){
TencentLocationRequest request = TencentLocationRequest.create();
request.setInterval(1000);
request.setRequestLevel(4);
request.setAllowCache(true);
Context context=this;
TencentLocationListener tencentLocationListener=this;
TencentLocationManager locationManager=TencentLocationManager.getInstance(context);
int error=locationManager.requestLocationUpdates(request,tencentLocationListener);
if(error==0){
Log.v("this"," Registration of location listener succeeded !");
}else {
Log.v("this"," Failed to register location listener !");
}
}
Callback during location update
@Override
public void onLocationChanged(TencentLocation tencentLocation, int i, String s) {
if (TencentLocation.ERROR_OK == i) {
// Positioning successful
if(tencentLocation!=null){
double lat=tencentLocation.getLatitude();
double lon=tencentLocation.getLongitude();
double accuracy=tencentLocation.getAccuracy();// precision
String nation=tencentLocation.getNation();// Country
String province=tencentLocation.getProvince();// Province
String city =tencentLocation.getCity();// City
String district=tencentLocation.getDistrict();// District
String town=tencentLocation.getTown();// The town of
String street=tencentLocation.getStreet();// The street
String streetNo=tencentLocation.getStreetNo();// House number
String add=nation+province+city+district+town+street+streetNo;
loc_tencent.setText(" Tencent positioning :"+" latitude :"+lat+"|"+" longitude :"+lon+"|"
+" precision :"+accuracy+"|"+" Address information :"+add);
moveTo(lat,lon,town,add);
}
} else {
// seek failed
Log.v("this", " seek failed !");
}
}
Locate the center and move the window
public void moveTo(double lat,double lon,String street,String add){
LatLng centPosition = new LatLng(lat,lon);
CameraUpdate cameraSigma=CameraUpdateFactory.newCameraPosition(new CameraPosition(
centPosition,// New center point coordinates
17,// New zoom level
0,// Pitch angle 0~45°( The vertical map is 0)
0// Yaw angle 0~360°( Due north 0)
));
final Marker marker = tencentMap.addMarker(new MarkerOptions().
position(centPosition).
title(street).
snippet(add));
marker.setIcon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_location));// Create icons
tencentMap.moveCamera(cameraSigma);
}
7.DEMO example
Screenshot of effect display Interested students , Sure Click here to download Source code .
边栏推荐
猜你喜欢
Vivo official website app full model UI adaptation scheme
[machine learning] dimension reduction technology PCA
DoTweenPath的具体使用实例
Alibaba cloud toolkit one click automatic deployment of jar packages
[machine learning] hierarchical clustering
Deque容器的系列操作( 详解 )
Harbor warehouse construction and simple use
Stream流对List集合筛选重复字段
Harbor仓库搭建及简单使用
jenkins:构建的时候进入子目录然后在进行mvn操作
随机推荐
问一下REITs是什么呢?请问,手机开户股票开户安全吗?
JS how to get the value and text content of the select drop-down box
高德地图在Geoserver图层上定位出现偏移的解决办法
Deque容器的系列操作( 详解 )
Digitalization of museums - development of digital collections app
[paper notes] objectbox: from centers to boxes for anchor free object detection
Mongodb get started
jenkins:构建的时候进入子目录然后在进行mvn操作
day 4 (项目一:家庭收支记录)
Go之数组/切片
3分钟掌握hook在typescript中的姿势
Use of delete
Jenkins安装并配置加速器
绝地求生 吃鸡 f12 截图保存路径参考
String类常用方法
游戏中的数学之角与弧度、三角函数
The list set is de duplicated according to the object attributes
Linux Installation mysql8 (Xiaobai must see)
看界面控件DevExpress WinForms——如何自定义辅助功能属性(下)
简析redux技术栈(二):认识saga的buffer和chanel