Giter Site home page Giter Site logo

rn-hms-demo's Introduction

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.

rn-hms-demo's People

Contributors

onurkenis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rn-hms-demo's Issues

onMessageReceived undefined is not a function

Currently i'm working in project that implement hms sdk in react native and i have this issue.

How to use method onMessageReceived in react native ?

import {RNHmsMessaging} from 'react-native-hwpush';

useEffect(() => {
AppState.addEventListener('PushMsgReceiverEvent', listenerPushMsg);

return () => {
  AppState.removeEventListener('PushMsgReceiverEvent', listenerPushMsg);
};

}, []);

const listenerPushMsg = event => {
RNHmsMessaging.onMessageReceived(msg => console.log(msg));
};

Anyway thanks for help

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.