Giter Club home page Giter Club logo

Ionic HMS Map Demo

An Ionic sample integrated with HMS Map Kit JavaScript Api.

Ionic HMS Map mobile

Running the application

Adding HMS API Key

  1. Copy your API Key from following section
AppGallery Connect > Your App > Develop > Overview > App Information > API key
  1. Open src/index.html

  2. Modify loadMapScript() function and paste your API Key here

const apiKey = encodeURIComponent("YOUR_API_KEY");
const src = `https://mapapi.cloud.huawei.com/mapjs/v1/api/js?callback=initMap&key=${apiKey}`;

const mapScript = document.createElement('script');
mapScript.setAttribute('src', src);
document.head.appendChild(mapScript);

Run Locally in a Web Browser

  1. Add your HMS API Key

  2. Install dependencies

cd ionic-hms-map-demo
npm install
  1. Run following command and you can visit http://localhost:8100/ in your web browser to see the app in action
ionic serve

Running on Android

  1. Add your HMS API Key

  2. Install dependencies

cd ionic-hms-map-demo
npm install
  1. Build Ionic app with the following command
ionic build
  1. Manually add the Android project.
npx cap add android
  1. Build and run the Ionic App using Android Studio. Once Android Studio launches, you can build/emulate/run your app through the standard Android Studio workflow.
npx cap open android

If you are having issues, you can follow getting started.

HMS Map Kit JavaScript API

  1. Provide the HUAWEI Map Kit API file. The key must be transcoded using the URL
<script src="https://mapapi.cloud.huawei.com/mapjs/v1/api/js?callback=initMap&key=API KEY"></script>
  1. Create map container elements in the body
<div id="map"></div> 
  1. Initialize the map. The following sample code is to create a map with Paris as the center and a zoom level of 8:
function initMap() { 
    const mapOptions = {}; 
    mapOptions.center = {lat: 48.856613, lng: 2.352222}; 
    mapOptions.zoom = 8; 
    mapOptions.language='ENG'; 
    const map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions); 
} 
  1. Adding Marker
const mMarker = new HWMapJsSDK.HWMarker({ 
    map: map, 
    position: {lat: 48.85, lng: 2.35}, 
    label: 'A', 
    icon: { 
        opacity: 0.5 
    } 
}); 
  1. Showing Information Window
const infoWindow = new HWMapJsSDK.HWInfoWindow({ 
    map, 
    position: 10, 
    content: 'This is a InfoWindow.', 
    offset: [0, -40], 
}); 

infoWindow.open(mMarker); 

mMarker.addListener('click', () => { 
    infoWindow.open(mMarker); 
}); 

Ionic HMS Map web

You can have more infromation from the official documentation of Huawei Map Kit - JS API and you can integrate it in any JS based project.

Onur Kenis's Projects

bucket-to-ipfs icon bucket-to-ipfs

This API handles pinning a file to IPFS which is uploaded to a specific Google Bucket.

dapp-sample icon dapp-sample

A sample full stack dApp with React, Ethers.js, Solidity, and Hardhat

flagkit icon flagkit

Beautiful flag icons for usage in apps and on the web.

ionic-hms icon ionic-hms

An Ionic Capacitor sample project with HMS integration

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.