Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/halilozel1903/huaweimapkitapp

An Android application related to Huawei Map Kit. đŸ—ē
https://github.com/halilozel1903/huaweimapkitapp

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

Last synced: 3 months ago
JSON representation

An Android application related to Huawei Map Kit. đŸ—ē

Awesome Lists containing this project

README

        

# Huawei Map Kit App đŸ—ē 📍 🧭

![Screenshot](https://github.com/halilozel1903/HuaweiMapKitApp/blob/master/photos/huawei.png)

## 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://github.com/halilozel1903/HuaweiMapKitApp/blob/master/photos/huaweiDeveloperAccount.png)

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

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

![Screenshot](https://github.com/halilozel1903/HuaweiMapKitApp/blob/master/photos/huaweiProject.png)

- And open an application in the project.

![Screenshot](https://github.com/halilozel1903/HuaweiMapKitApp/blob/master/photos/huaweiApp.png)

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

![Screenshot](https://github.com/halilozel1903/HuaweiMapKitApp/blob/master/photos/huaweiSettings.png)

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

![Screenshot](https://github.com/halilozel1903/HuaweiMapKitApp/blob/master/photos/gradleSign.png)

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

![Screenshot](https://github.com/halilozel1903/HuaweiMapKitApp/blob/master/photos/sha256.png)

- Need to activate MapKit from the Manage API section.

![Screenshot](https://github.com/halilozel1903/HuaweiMapKitApp/blob/master/photos/huaweiMapKit.png)

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

![Screenshot](https://github.com/halilozel1903/HuaweiMapKitApp/blob/master/photos/agconnect.png)

- Define the necessary permissions in the `AndroidManifest.xml` file.

```kotlin

```

- In the `build.gradle(HuaweiMapKitApp)` field, we add the necessary codes for Huawei Map Kit.

```kotlin
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)`

```kotlin
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.huawei.agconnect'
}
```

- Add the Map Kit dependency in `build.gradle(:app)`

```kotlin
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`).

```kotlin

```

- Make map settings in the `MainActivity.kt`. Add a static location information and marker to the map.

```kotlin
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 📚
- https://developer.huawei.com/consumer/en/hms/huawei-MapKit/
- https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-sdk-introduction-0000001050158633
- https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/hms-map-v4-faq
- https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-sdk-version-change-history-0000001050156688


## 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.
```