Giter Site home page Giter Site logo

halilozel1903 / huaweimapkitapp Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 7.88 MB

An Android application related to Huawei Map Kit. ๐Ÿ—บ

Home Page: https://halilozel1903.medium.com/huawei-map-kit-d436944b1773

Kotlin 100.00%
huawei huawei-mobile-services huawei-maps huawei-map-kit map android android-application android-app android-map huawei-sdk hms hms-map hms-sample hmscore kotlin-android kotlin-language android-sdk android-maps hms-location hmsbuild

huaweimapkitapp's Introduction

Huawei Map Kit App ๐Ÿ—บ ๐Ÿ“ ๐Ÿงญ

Screenshot

What is Huawei Map Kit โ‰๏ธ

Map Kit is an SDK for map development. It covers map data of more than 200 countries and regions, and supports hundreds of languages. With this SDK, you can easily integrate map-based functions into your apps.

HUAWEI Map Kit uses the WGS 84 GPS coordinate system, which meets most map development requirements outside China, including: Map display: Displays buildings, roads, water systems, and Points of Interest (POIs). Map interaction: Controls the interaction gestures and buttons on the map. Map drawing: Adds location markers, map layers, overlays, and various shapes.

How to use Huawei Map Kit ๐Ÿง

  • First, you need to register a Huawei Developer account. You can register it for free from the link below.

Screenshot

https://id5.cloud.huawei.com/CAS/portal/userRegister/regbyemail.html

  • After opening the developer account, we will create a project

Screenshot

  • And open an application in the project.

Screenshot

  • Need to adjust the settings of the application. Since it is a sample project, I share all the information with you.

Screenshot

  • Need to produce SHA-256 certificate fingerprints. We click on the Gradle area on the right in Android Studio.

Screenshot

  • Clicking the signingReport button under Tasks, we generate sha 256 code. We add it to the relevant field in the project settings.

Screenshot

  • Need to activate MapKit from the Manage API section.

Screenshot

  • Download the agconnect-services.json file. Then we add it to the app folder of our project.

Screenshot

  • Define the necessary permissions in the AndroidManifest.xml file.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.huawei.appmarket.service.commondata.permission.GET_COMMON_DATA" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

  • In the build.gradle(HuaweiMapKitApp) field, we add the necessary codes for Huawei Map Kit.
buildscript {
    ext.kotlin_version = "1.6.21"
    repositories {
        google()
        mavenCentral()
        maven { url 'https://developer.huawei.com/repo/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.huawei.agconnect:agcp:1.6.0.300'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://developer.huawei.com/repo/'
        }
    }
}

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

  • Add the plugin in build.gradle(:app)
plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'com.huawei.agconnect'
}

  • Add the Map Kit dependency in build.gradle(:app)
dependencies {
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.huawei.hms:maps:6.4.1.300'
}

  • Now can add map to our layout file (activity_main.xml).
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.huawei.hms.maps.MapView
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:id="@+id/huaweiMapView"
        map:uiCompass="true"
        map:uiZoomControls="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

  • Make map settings in the MainActivity.kt. Add a static location information and marker to the map.
class MainActivity : AppCompatActivity(), OnMapReadyCallback {

    private lateinit var huaweiMap: HuaweiMap
    private lateinit var marker: Marker
    private lateinit var cameraUpdate: CameraUpdate
    private lateinit var cameraPosition: CameraPosition
    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // View Binding Settings
        binding = ActivityMainBinding.inflate(layoutInflater)
        val view = binding.root
        setContentView(view)

        var mapViewBundle: Bundle? = null
        if (savedInstanceState != null) {
            mapViewBundle = savedInstanceState.getBundle(MAP_BUNDLE_KEY)
        }
        binding.huaweiMapView.onCreate(mapViewBundle)
        binding.huaweiMapView.getMapAsync(this)
    }


    // if the map is ready
    override fun onMapReady(map: HuaweiMap) {

        // mapping
        huaweiMap = map

        // marker add
        marker = huaweiMap.addMarker(
            MarkerOptions()
                .icon(BitmapDescriptorFactory.defaultMarker()) // default marker
                .title("Huawei Turkey") // maker title
                .position(LatLng(41.031261, 29.117277)) // marker position

        )
        // camera position settings
        cameraPosition = CameraPosition.builder()
            .target(LatLng(41.031261, 29.117277))
            .zoom(10f)
            .bearing(2.0f)
            .tilt(2.5f).build()
        cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition)
        huaweiMap.moveCamera(cameraUpdate)

    }
    // constant
    companion object {
        private const val MAP_BUNDLE_KEY = "MapBundleKey"
    }
}
  • Have done all the necessary actions. Congratulations! ๐Ÿฅณ You have developed the first Huawei Maps application.

Screenshots ๐Ÿ“ฑ

Resources ๐Ÿ“š


License โ„น๏ธ

MIT License

Copyright (c) 2022 Halil OZEL

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

huaweimapkitapp's People

Contributors

halilozel1903 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

drmuzi

huaweimapkitapp's Issues

Map is not rendering

Hello, how are you?

I created my own project, In Huawei dev console, downloaded ag-connect-service file, and changed the app id. Unfortunately, the map is not rendering (https://drive.google.com/file/d/1KutW6FdLzYYF9hJ_Y4FSzvVWqWr4Zobs/view?usp=sharing) .what could be the issue?

by the way, I enabled both Map kit and Location API. Also, there is these errors displayed in logcat:

2021-09-21 15:00:34.258 17384-17637/com.marsa.store E/HmsMapKit_TileCache_38: startUrlRequest Identity fail, do not has permission get tile. authResult :6


2021-09-21 15:00:49.986 17384-17563/com.marsa.store E/HmsMapKit_MapDataVersionClient_28: Exception occur
    com.huawei.hms.maps.foundation.client.mac: * * *E*U*S*_*E*I*D
        at com.huawei.hms.maps.foundation.client.mac$maa.b(Unknown Source:25)
        at com.huawei.hms.maps.foundation.client.mab.a(Unknown Source:20)
        at com.huawei.hms.maps.foundation.client.mab.c(Unknown Source:80)
        at com.huawei.hms.maps.foundation.client.mab.a(Unknown Source:88)
        at com.huawei.hms.maps.foundation.client.mab.a(Unknown Source:1)
        at com.huawei.hms.maps.provider.client.dataversion.maa.m(Unknown Source:2)
        at com.huawei.hms.maps.provider.client.dataversion.maa.lambda$VkLWwzu7W690n_qHxpBFU9o7rLI(Unknown Source:0)
        at com.huawei.hms.maps.provider.client.dataversion.-$$Lambda$maa$VkLWwzu7W690n_qHxpBFU9o7rLI.call(Unknown Source:4)
        at com.huawei.hms.maps.foundation.client.mab$maa.a(Unknown Source:3)
        at com.huawei.hms.maps.provider.client.dataversion.maa.e(Unknown Source:28)
        at com.huawei.hms.maps.provider.client.dataversion.maa.d(Unknown Source:4)
        at com.huawei.hms.maps.provider.cache.mac$maa.a(Unknown Source:0)
        at com.huawei.hms.maps.provider.cache.mac$maa.call(Unknown Source:0)
        at mnr.b(Unknown Source:17)
        at mma.a(Unknown Source:14)
        at mnv$mab.run(Unknown Source:6)
        at mmd$maa.run(Unknown Source:9)
        at moh.run(Unknown Source:13)
        at moh.call(Unknown Source:0)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)
2021-09-21 15:00:49.993 17384-17563/com.marsa.store E/HmsMapKit_ErrorTraceLogPusher_4: cache error trace log : ErrorTraceLogDTO{ scenario = ACCESS_SERVICE_ERROR', message='6 : REQUEST_DENIED'}
    com.huawei.hms.maps.foundation.client.mac: * * *E*U*S*_*E*I*D
        at com.huawei.hms.maps.foundation.client.mac$maa.b(Unknown Source:25)
        at com.huawei.hms.maps.foundation.client.mab.a(Unknown Source:20)
        at com.huawei.hms.maps.foundation.client.mab.c(Unknown Source:80)
        at com.huawei.hms.maps.foundation.client.mab.a(Unknown Source:88)
        at com.huawei.hms.maps.foundation.client.mab.a(Unknown Source:1)
        at com.huawei.hms.maps.provider.client.dataversion.maa.m(Unknown Source:2)
        at com.huawei.hms.maps.provider.client.dataversion.maa.lambda$VkLWwzu7W690n_qHxpBFU9o7rLI(Unknown Source:0)
        at com.huawei.hms.maps.provider.client.dataversion.-$$Lambda$maa$VkLWwzu7W690n_qHxpBFU9o7rLI.call(Unknown Source:4)
        at com.huawei.hms.maps.foundation.client.mab$maa.a(Unknown Source:3)
        at com.huawei.hms.maps.provider.client.dataversion.maa.e(Unknown Source:28)
        at com.huawei.hms.maps.provider.client.dataversion.maa.d(Unknown Source:4)
        at com.huawei.hms.maps.provider.cache.mac$maa.a(Unknown Source:0)
        at com.huawei.hms.maps.provider.cache.mac$maa.call(Unknown Source:0)
        at mnr.b(Unknown Source:17)
        at mma.a(Unknown Source:14)
        at mnv$mab.run(Unknown Source:6)
        at mmd$maa.run(Unknown Source:9)
        at moh.run(Unknown Source:13)
        at moh.call(Unknown Source:0)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)
2021-09-21 15:00:50.001 17384-17563/com.marsa.store W/HmsMapKit_ErrorTraceLogPusher_36: log push is not allow.
2021-09-21 15:00:50.004 17384-17563/com.marsa.store E/HmsMapKit_MapDataVersionCache_21: mapStyleVersion is invalid, start retry...
2021-09-21 15:00:50.012 17384-17384/com.marsa.store E/HmsMapKit_TileCache_4: query mapDataVersion failed!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.