map
This commit is contained in:
parent
28cfbc35db
commit
5c0686b778
|
@ -50,5 +50,7 @@ dependencies {
|
|||
implementation ("io.github.lucksiege:ucrop:v3.11.2")
|
||||
implementation ("io.github.lucksiege:camerax:v3.11.2")
|
||||
implementation ("com.github.bumptech.glide:glide:4.15.1")
|
||||
//权限
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
|
||||
|
@ -11,27 +12,36 @@
|
|||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||
<!-- 访问网络,进行地图相关业务数据请求,包括地图数据,路线规划,POI检索等 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- 获取网络状态,根据网络状态切换进行数据请求网络转换 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<!-- 读取外置存储。如果开发者使用了so动态加载功能并且把so文件放在了外置存储区域,则需要申请该权限,否则不需要 -->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<!-- 写外置存储。如果开发者使用了离线地图,并且数据写在外置存储区域,则需要申请该权限 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<!-- 这个权限用于进行网络定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<!-- 这个权限用于访问GPS定位 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
|
||||
<queries package="${applicationId}">
|
||||
<intent>
|
||||
<action android:name="android.media.action.IMAGE_CAPTURE">
|
||||
|
||||
</action>
|
||||
<action android:name="android.media.action.IMAGE_CAPTURE"></action>
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.media.action.ACTION_VIDEO_CAPTURE">
|
||||
|
||||
</action>
|
||||
<action android:name="android.media.action.ACTION_VIDEO_CAPTURE"></action>
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:name=".DemoApplication"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
@ -42,6 +52,12 @@
|
|||
android:theme="@style/Theme.MyProject"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:targetApi="31">
|
||||
<meta-data
|
||||
android:name="com.baidu.lbsapi.API_KEY"
|
||||
android:value="01VrbOjU0YWyvJ6NChF3MgB8FOTXUvai" />
|
||||
<activity
|
||||
android:name=".MapActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".ClockActivity"
|
||||
android:exported="false" />
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.hnucm.c202201020328;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.baidu.location.LocationClient;
|
||||
import com.baidu.mapapi.CoordType;
|
||||
import com.baidu.mapapi.SDKInitializer;
|
||||
|
||||
public class DemoApplication extends Application {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
SDKInitializer.setAgreePrivacy(getApplicationContext(),true);
|
||||
SDKInitializer.initialize(getApplicationContext());
|
||||
SDKInitializer.setCoordType(CoordType.BD09LL);
|
||||
LocationClient.setAgreePrivacy(true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
package com.hnucm.c202201020328;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.baidu.location.BDAbstractLocationListener;
|
||||
import com.baidu.location.BDLocation;
|
||||
import com.baidu.location.LocationClient;
|
||||
import com.baidu.location.LocationClientOption;
|
||||
import com.baidu.mapapi.map.BaiduMap;
|
||||
import com.baidu.mapapi.map.MapStatus;
|
||||
import com.baidu.mapapi.map.MapStatusUpdateFactory;
|
||||
import com.baidu.mapapi.map.MapView;
|
||||
import com.baidu.mapapi.map.MyLocationData;
|
||||
import com.baidu.mapapi.model.LatLng;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
import com.permissionx.guolindev.PermissionX;
|
||||
import com.permissionx.guolindev.callback.RequestCallback;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MapActivity extends Activity {
|
||||
private MapView mMapView = null;
|
||||
BaiduMap mBaiduMap;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_map);
|
||||
|
||||
//设定中心点坐标
|
||||
mMapView = (MapView) findViewById(R.id.bmapView);
|
||||
mBaiduMap = mMapView.getMap();
|
||||
// 设置空白地图
|
||||
mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
|
||||
//设定中心点坐标
|
||||
mBaiduMap.setBuildingsEnabled(true);
|
||||
LatLng cenpt = new LatLng(28.135339, 112.900747);
|
||||
MapStatus.Builder builder = new MapStatus.Builder();
|
||||
builder.zoom(18.0f)
|
||||
.target(cenpt);
|
||||
mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
|
||||
|
||||
mBaiduMap.setMyLocationEnabled(true);
|
||||
|
||||
//定位初始化
|
||||
LocationClient mLocationClient = null;
|
||||
try {
|
||||
mLocationClient = new LocationClient(this);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
//通过LocationClientOption设置LocationClient相关参数
|
||||
LocationClientOption option = new LocationClientOption();
|
||||
option.setOpenGps(true); // 打开gps
|
||||
option.setCoorType("bd09ll"); // 设置坐标类型
|
||||
option.setScanSpan(1000);
|
||||
|
||||
//设置locationClientOption
|
||||
mLocationClient.setLocOption(option);
|
||||
|
||||
//注册LocationListener监听器
|
||||
MyLocationListener myLocationListener = new MyLocationListener();
|
||||
mLocationClient.registerLocationListener(myLocationListener);
|
||||
//开启地图定位图层
|
||||
mLocationClient.start();
|
||||
}
|
||||
public class MyLocationListener extends BDAbstractLocationListener {
|
||||
@Override
|
||||
public void onReceiveLocation(BDLocation location) {
|
||||
//mapView 销毁后不在处理新接收的位置
|
||||
if (location == null || mMapView == null){
|
||||
return;
|
||||
}
|
||||
Log.i("test",location.getLatitude()+":"+location.getLongitude());
|
||||
MyLocationData locData = new MyLocationData.Builder()
|
||||
.accuracy(location.getRadius())
|
||||
// 此处设置开发者获取到的方向信息,顺时针0-360
|
||||
.direction(location.getDirection()).latitude(location.getLatitude())
|
||||
.longitude(location.getLongitude()).build();
|
||||
mBaiduMap.setMyLocationData(locData);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -68,7 +68,7 @@ public class ToolActivity extends AppCompatActivity {
|
|||
constraintLayout.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent=new Intent(ToolActivity.this, Date_dayActivity.class);
|
||||
Intent intent=new Intent(ToolActivity.this, MapActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
@ -87,6 +87,14 @@ public class ToolActivity extends AppCompatActivity {
|
|||
|
||||
}
|
||||
});
|
||||
ImageView imageView13=findViewById(R.id.imageView13);
|
||||
imageView13.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent=new Intent(ToolActivity.this,MapActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
mContentExpandTextView = (ExpandTextView) findViewById(R.id.txt_content);
|
||||
mContentExpandTextView.initWidth(getWindowManager().getDefaultDisplay().getWidth());
|
||||
// 设置最大行数
|
||||
|
|
|
@ -7,4 +7,22 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".Date_dayActivity">
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="按日" />
|
||||
|
||||
<com.google.android.material.tabs.TabItem
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="按月" />
|
||||
|
||||
</com.google.android.material.tabs.TabLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MapActivity">
|
||||
|
||||
<com.baidu.mapapi.map.MapView
|
||||
android:id="@+id/bmapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue