This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1187 from GBSTS/master
- Loading branch information
Showing
5 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="edu.hzuapps.androidlabs"> | ||
<!-- | ||
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use | ||
Google Maps Android API v2, but you must specify either coarse or fine | ||
location permissions for the "MyLocation" functionality. | ||
--> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 访问网络,进行地图相关业务数据请求,包括地图数据,路线规划,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" /> | ||
|
||
<application | ||
android:name=".MapApplication" | ||
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/AppTheme"> | ||
<activity android:name=".MapActivity"></activity> | ||
|
||
<meta-data | ||
android:name="com.baidu.lbsapi.API_KEY" | ||
android:value="nn8i3si7MoaCtYBQDGGv1dcZuVW0SWDB" /> | ||
<!-- | ||
The API key for Google Maps-based APIs is defined as a string resource. | ||
(See the file "res/values/google_maps_api.xml"). | ||
Note that the API key is linked to the encryption key used to sign the APK. | ||
You need a different API key for each encryption key, including the release key that is used to | ||
sign the APK for publishing. | ||
You can define the keys for the debug and release targets in src/debug/ and src/release/. | ||
--> | ||
<activity android:name=".MainActivity" /> | ||
<activity android:name=".Net1814080903118LendAckActivity" /> | ||
<activity android:name=".Net1814080903118PayAckActivity" /> | ||
<activity android:name=".Net1814080903118PersonalActivity" /> | ||
<activity android:name=".Net1814080903118WorkLendActivity" /> | ||
<activity android:name=".Net1814080903118WorkUnLendActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package edu.hzuapps.androidlabs; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
|
||
import com.baidu.mapapi.map.MapView; | ||
|
||
public class MapActivity extends Activity { | ||
|
||
private MapView mMapView = null; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_map); | ||
//获取地图控件引用 | ||
mMapView = (MapView) findViewById(R.id.bmapView); | ||
} | ||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
//在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理 | ||
mMapView.onResume(); | ||
} | ||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
//在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理 | ||
mMapView.onPause(); | ||
} | ||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理 | ||
mMapView.onDestroy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package edu.hzuapps.androidlabs; | ||
|
||
import android.app.Application; | ||
|
||
import com.baidu.mapapi.CoordType; | ||
import com.baidu.mapapi.SDKInitializer; | ||
|
||
public class MapApplication extends Application { | ||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
//在使用SDK各组件之前初始化context信息,传入ApplicationContext | ||
SDKInitializer.initialize(this); | ||
//自4.3.0起,百度地图SDK所有接口均支持百度坐标和国测局坐标,用此方法设置您使用的坐标类型. | ||
//包括BD09LL和GCJ02两种坐标,默认是BD09LL坐标。 | ||
SDKInitializer.setCoordType(CoordType.BD09LL); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "30.0.2" | ||
|
||
defaultConfig { | ||
applicationId "edu.hzuapps.androidlabs" | ||
minSdkVersion 25 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
sourceSets { | ||
main { | ||
jniLibs.srcDir 'libs' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: "libs", include: ["*.jar"]) | ||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.1' | ||
implementation 'com.google.android.gms:play-services-maps:17.0.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# 实验六:Android网络编程 | ||
|
||
## 一、实验目标 | ||
|
||
1. 掌握Android网络访问方法; | ||
2. 理解XML和JSON表示数据的方法。 | ||
|
||
## 二、实验内容 | ||
|
||
因为本人的项目不涉及这方面的内容因此本人选择完成引入地图来实现本人项目的一部分功能 | ||
|
||
## 三、实验步骤 | ||
|
||
1. 从百度地图的官方网站下载百度地图的SDK | ||
|
||
2. 获取地图的开发密钥 | ||
|
||
3. 引入百度SDK到本人的项目 | ||
|
||
3.1 把`BaiduLBS_Android.jar`放在`app/libs`下,并且通过右键点击`Add As Library`来把这个`.jar`文件加载进入项目 | ||
|
||
3.2 往项目中添加so文件, 在下载的开发包中拷贝需要的CPU架构对应的so文件文件夹到`app/libs`目录下 | ||
|
||
4. 配置`AndroidManifest.xml`文件 | ||
|
||
4.1 在`<application>`中加入如下代码配置开发密钥(AK): | ||
|
||
```xml | ||
<application> | ||
<meta-data | ||
android:name="com.baidu.lbsapi.API_KEY" | ||
android:value="开发者 key" /> | ||
</application> | ||
``` | ||
|
||
4.2 在`<application>`外部添加如下权限声明: | ||
|
||
```xml | ||
<!-- 访问网络,进行地图相关业务数据请求,包括地图数据,路线规划,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" /> | ||
``` | ||
|
||
5. 新建一个自定义的`Application`,在其`onCreate`方法中完成SDK的初始化。 | ||
|
||
```java | ||
package edu.hzuapps.androidlabs; | ||
|
||
import android.app.Application; | ||
|
||
import com.baidu.mapapi.CoordType; | ||
import com.baidu.mapapi.SDKInitializer; | ||
|
||
public class MapApplication extends Application { | ||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
//在使用SDK各组件之前初始化context信息,传入ApplicationContext | ||
SDKInitializer.initialize(this); | ||
//自4.3.0起,百度地图SDK所有接口均支持百度坐标和国测局坐标,用此方法设置您使用的坐标类型. | ||
//包括BD09LL和GCJ02两种坐标,默认是BD09LL坐标。 | ||
SDKInitializer.setCoordType(CoordType.BD09LL); | ||
} | ||
} | ||
|
||
``` | ||
|
||
6. 创建地图`Activity`,管理`MapView`生命周期 | ||
|
||
```java | ||
package edu.hzuapps.androidlabs; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
|
||
import com.baidu.mapapi.map.MapView; | ||
|
||
public class MapActivity extends Activity { | ||
|
||
private MapView mMapView = null; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_map); | ||
//获取地图控件引用 | ||
mMapView = (MapView) findViewById(R.id.bmapView); | ||
} | ||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
//在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理 | ||
mMapView.onResume(); | ||
} | ||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
//在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理 | ||
mMapView.onPause(); | ||
} | ||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
//在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理 | ||
mMapView.onDestroy(); | ||
} | ||
} | ||
``` | ||
|
||
7. 在`MapActivity.java`文件对应的布局文件中加入`MapView` | ||
|
||
```xml | ||
<?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: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> | ||
``` | ||
|
||
## 四、运行结果及截图 | ||
|
||
[![D6gG8I.png](https://s3.ax1x.com/2020/11/29/D6gG8I.png)](https://imgchr.com/i/D6gG8I) | ||
|
||
## 五、心得体会 | ||
|
||
通过本次的实验,本人学会了怎么在Android中使用Map,本人认为能够使用Map对应Android应用而言是非常重要的。因为在当下,我们很多的活动合作一些工作都需要使用到定位或者查看当前位置的功能。如果没有Map的这个功能的话,我们的活动活动都无法完成。 |