原生Android空白项目引入腾讯地图

https://blog.csdn.net/weixin_45143788/article/details/127498365
安装教程

 

https://www.cnblogs.com/R-bear/p/18076117
第一次运行项目

 

注意:

一定要认真添加运行设备并下载设备运行环境

一定要等待下面的importing完成才可以运行项目

慢的时候可以引入镜像

maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }


gradle版本下载慢的情况可以使用镜像

官网地址:https://services.gradle.org/distributions/

腾讯云镜像 Gradle下载地址:https://mirrors.cloud.tencent.com/gradle/

阿里云镜像 Gradle下载地址:https://mirrors.aliyun.com/macports/distfiles/gradle/

阿里云镜像 Gradle下载地址:https://mirrors.aliyun.com/gradle/

#Thu Dec 27 14:03:13 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https://mirrors.aliyun.com/gradle/gradle-4.10.1-all.zip

  




配置版本要求
gradle版本1.8



# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

# 导航核心库
-keep class com.tencent.navix.**{*;}
-keep class com.tencent.gaya.**{*;}
-keep class com.tencent.map.**{*;}
-keep class com.tencent.mapsdk.**{*;}
-keep class com.tencent.tencentmap.**{*;}
-keep class com.tencent.bugly.**{*;}
-keep class com.tencent.feedback.**{*;}
-keep class com.tencent.tmsbeacon.**{*;}
-keep class com.tencent.tmsqmsp.**{*;}
-keep class com.tencent.lbssearch.**{*;}
-keep class com.tencent.moduleSDK.**{*;}
-keep class com.tencent.pangu.**{*;}
-keep class com.qq.taf.**{*;}
-keep class com.qq.jce.**{*;}
-keep class c.t.**{*;}

# TTS库
-keep class com.tencent.ai.**{*;}
-keep class com.tencent.btts.**{*;}
-keep class kael.tools.log.**{*;}
-keep class qrom.component.log.**{*;}

-keep class com.tencent.beacontmap.** { *; }
proguard-rules.pro
 
plugins {
    id 'com.android.application'
}
android {
    compileSdkVersion 34

    defaultConfig {
        applicationId "com.example.test_application3"
        minSdk 24
        targetSdkVersion 34
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

//    implementation libs.appcompat
//    implementation libs.material
//    implementation libs.activity
//    implementation libs.constraintlayout
//    testImplementation libs.junit
//    androidTestImplementation libs.ext.junit
//    androidTestImplementation libs.espresso.core
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    // 导航核心库
    implementation "com.tencent.map:tencent-map-nav-sdk-core:6.12.1"
    // 基础依赖
    implementation "com.tencent.openmap:foundation:0.5.5.2da11df-lite"
    // 导航内置TTS,可选
    implementation "com.tencent.map:tencent-map-nav-sdk-tts:6.12.1"
}
build.gradle

 

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
    }

}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }

        maven {
            url "https://mirrors.tencent.com/repository/maven/tencent_public/"
        }
        maven {
            url "https://mirrors.tencent.com/repository/maven/tencent_public_snapshots"
        }
        google()
//        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
build.gradle

 

package com.example.test_application3;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Build;
import android.os.Bundle;

import com.example.test_application3.R;

import com.tencent.map.geolocation.TencentLocationManager;
import com.tencent.navix.api.NavigatorConfig;
import com.tencent.navix.api.NavigatorZygote;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.TencentMapInitializer;
import com.tencent.tencentmap.mapsdk.maps.TextureMapView;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;

public class MapLauncherActivity extends AppCompatActivity {

    private TextureMapView mapView;
    private TencentMap tencentMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化
        TencentMapInitializer.setAgreePrivacy(this.getApplicationContext(), true);
        TencentMapInitializer.start(this.getApplicationContext());
        NavigatorZygote.with(getApplicationContext()).init(
                NavigatorConfig.builder()
                        .setUserAgreedPrivacy(true)     // 设置同意隐私协议
                        .setDeviceId("custom_device_id")    // 设置自定义的设备ID,用于问题排查(只以首次设置为准)
                        .setDeviceModel(Build.MODEL)        // 设置设备型号,帮助问题排查
                        .setDeveloperKey("")   // 设置开发者KEY
                        .build()
        );

// 注意:6.11.0开始需要同意隐私后再启动导航
        NavigatorZygote.with(getApplicationContext()).start();
        // 初始化地图视图
        mapView = findViewById(R.id.mapview);
        tencentMap = mapView.getMap();

        // 设置地图默认显示位置和缩放级别
        setupDefaultMapView();
    }

    private void setupDefaultMapView() {
        // 设置地图中心点为北京,缩放级别12
        LatLng defaultLatLng = new LatLng(39.9042, 116.4074);
        tencentMap.moveCamera(CameraUpdateFactory.newLatLngZoom(defaultLatLng, 12));

//         启用缩放控件
        tencentMap.getUiSettings().setZoomControlsEnabled(true);

//         禁用所有手势(可选)
//         tencentMap.getUiSettings().setAllGesturesEnabled(false);
    }

    // ========== 地图生命周期管理 ==========
    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

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

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

//    @Override
//    protected void onSaveInstanceState(@NonNull Bundle outState) {
//        super.onSaveInstanceState(outState);
//        mapView.onSaveInstanceState(outState);
//    }
//

//    @Override
//    public void onLowMemory() {
//        super.onLowMemory();
//        mapView.onLowMemory();
//    }
}
MapLauncherActivity

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.test_application3">

<!--    &lt;!&ndash; 通过GPS得到精确位置 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>-->
<!--    &lt;!&ndash; 通过网络得到粗略位置 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>-->
<!--    &lt;!&ndash; 访问网络,某些位置信息需要从网络服务器获取 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.INTERNET"/>-->
<!--    &lt;!&ndash; 访问WiFi状态,需要WiFi信息用于网络定位 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>-->
<!--    &lt;!&ndash; 修改WiFi状态,发起WiFi扫描, 需要WiFi信息用于网络定位 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>-->
<!--    &lt;!&ndash; 访问网络状态, 检测网络的可用性,需要网络运营商相关信息用于网络定位 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>-->
<!--    &lt;!&ndash; 访问网络的变化, 需要某些信息用于网络定位 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>-->
<!--    &lt;!&ndash; 蓝牙扫描权限 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.BLUETOOTH"/>-->
<!--    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>-->
<!--    &lt;!&ndash; 前台service权限 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>-->
<!--    &lt;!&ndash; 后台定位权限 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>-->
<!--    &lt;!&ndash; A-GPS辅助定位权限,方便GPS快速准确定位 &ndash;&gt;-->
<!--    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>-->

    <!-- 最基本的网络权限 -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:targetApi="p">

        <meta-data
            android:name="TencentMapSDK"
            android:value=""/>
<!--        <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>-->

        <activity android:name=".MapLauncherActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
AndroidManifest.xml

 

#Tue Apr 29 11:58:11 CST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
gradle-wrapper.properties
posted @ 2025-05-07 16:26  阿蒙不萌  阅读(37)  评论(0)    收藏  举报